我有一个Chrome扩展内容脚本,我想在Trello板上运行.现在,它只包含:
console.log("Hello,world!");
当您通过内部链接打开Trello板页面时,像My Boards页面那样,内容脚本不会运行.它在运行后刷新页面虽然.
我的清单文件包含:
{ "manifest_version": 2,"name": "Temp Ext","version": "1.0","content_scripts": [ { "matches": ["*://trello.com/b/*"],"js":["contentscript.js"] } ] }
任何人都可以帮助我找出为什么脚本在页面初始加载时不运行?
解决方法
问题是
Trello uses HTML5’s pushState用于页面转换,因此在打开单板后,内容脚本并不总是运行.
解
清单变更:
{ "manifest_version": 2,"version": "1.1","content_scripts": [{ "matches": ["*://trello.com/*"],"js":["contentscript.js"] }],"background": { "scripts": ["background.js"] },"permissions": [ "*://trello.com/*","tabs","webNavigation" ] }
添加背景脚本:
chrome.webNavigation.onHistoryStateUpdated.addListener(function(details) { chrome.tabs.executeScript(null,{file:"contentscript.js"}); });