【发布时间】:2015-07-17 13:22:26
【问题描述】:
见下面代码中的 cmets:
chrome.browserAction.onClicked.addListener(function(tab) {
// ################# This works without any problems
chrome.tabs.executeScript(tabId, {
code: '!!window.LoadedFlag'
}, function (hasContentJs) { ... });
chrome.tabs.onUpdated.addListener(function (tabId, changeInfo, tab) {
// ################# This throws error:
// Unchecked runtime.lastError while running tabs.executeScript:
// Cannot access contents of url "http://localhost:3000/". Extension manifest must request permission to access this host.
chrome.tabs.executeScript(tabId, {
code: '!!window.LoadedFlag'
}, function (hasContentJs) { ... });
我不允许在专门针对 chrome.tabs.onUpdated.addListener 的回调中执行 chrome.tabs.executeScript 吗?
我的用例是我需要在每次页面刷新时运行启动脚本,但前提是我的扩展程序已启用。
manifest.json:
"permissions" : [
"activeTab"
"tabs",
"http://*/*",
"https://*/*"
],
【问题讨论】:
-
您在设置新权限后是否重新加载了您的扩展程序?并且使用 onUpdated 并不是选择性地注入内容脚本的最佳方式。如需更好的选择,请参阅stackoverflow.com/questions/26667112/…