简体   繁体   中英

chrome.tabs.create not working properly?

IN THE MANIFEST:

{
"manifest_version": 2,
"version": "0.1",
"name": "test",
"description": "test",
"content_scripts": [
{
    "matches": ["http://www.roblox.com/*", "https://www.roblox.com/*"],
    "js": ["jquery.js", "ecyInject.js"]
},
{
    "matches": ["http://www.roblox.com/Economy"],
    "js": ["jquery.js", "ecyPage.js"]
}
],

"permissions": [
    "notifications", "tabs", "http://www.roblox.com/"
],

"background": {
    "page": "main.html"
}
}

Then this is the "main.html"

<html>
<head>
    <script src="jquery.js"></script>
    <script src="Services.js"></script>
    <script>
        chrome.tabs.create({url:("http://www.google.com/")});
    </script>
</head>

<body>

</body>
</html>

How come it doesn't open the homepage to www.google.com? The rest of the extension works, however its just the "chrome.tabs.create" part that doesn't. My extension does have tab permission, I don't see what could be wrong.

EDIT

"Refused to execute inline script because it violates the following Content Security Policy directive: "script-src 'self' chrome-extension-resource:"."

I just saw that error, anyway to prevent that? ^^^^

Chrome extensions aren't allowed to grab scripts that aren't within the extension or listed as a resource (as the error stated somewhat confusingly says). The CSP (content security policy) is something that you can define to change this behavior. The default would look like this:

"content_security_policy": "script-src 'self' chrome-extension-resource: ; object-src 'self'",

You probably want something like this:

"content_security_policy": "script-src 'self' chrome-extension-resource: http://www.google.com ; object-src 'self'",

Stick that line in your manifest.json :-)

More examples can be found here

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM