当我通过点击扩展图标运行下面的代码时,我会看到来自mainscript.js的'Mainscript'警告。
当我使用Dev-Tools调试器并暂停时:
chrome.tabs.executeScript(null, {file: "mainscript.js"}); in background.js
然后单击“继续”我收到错误消息:
Unchecked runtime.lastError while running tabs.executeScript: Cannot access contents of the page. Extension manifest must request permission to access the respective host.
我认为这是因为我现在正在调试器窗口的上下文中运行executeScript。
如何停止导致错误的调试器?
清单:
{
"name": "Enable/Disable",
"version": "1.0",
"manifest_version": 2,
"description": "Enables/Disables",
"permissions":
[
"http://xxx.xxx.xxx.xxx/*",
"activeTab"
],
"browser_action":
{
"default_icon":
{
"16": "images/Icon_ENABLED.png"
}
},
"background":
{
"scripts": ["background.js"]
}
}
background.js:
chrome.browserAction.onClicked.addListener
(
function(tab)
{
chrome.tabs.executeScript(null, {file: "mainscript.js"});
}
);
mainscript.js
alert('Mainscript');