我正在尝试在manifest.json
中获得本地主机权限,因此可以使用chrome.tabs.executeScript
,但是它不起作用。我已经尝试了几乎所有您能想到的。这是一个示例:
{
"manifest_version": 2,
"name": "extName",
"version": "1",
"description": "extDesc",
"content_scripts": [
{
"matches": [
"http://localhost:3000/*",
"http://127.0.0.1/*",
"http://*/*",
"https://*/*"
],
"css": [
"style.css"
],
"js": [
"contentScript.js"
]
}
],
"background": {
"scripts": [
"background.js"
]
},
"permissions": [
"activeTab",
"tabs"
]
}
但是无论我尝试什么,我都会不断得到
Error during tabs.executeScript: Cannot access contents of url ....
Extension manifest must request permission to access this host.
实际上,我认为这也没有在localhost
这是我的background.js:
chrome.runtime.onMessage.addListener(
function(message, callback) {
if (message == "runContentScript"){
chrome.tabs.executeScript(null, {
code: 'console.log(window.angular)'
});
}
});