简体   繁体   English

chrome.tabs.create无法正常工作?

[英]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" 这就是“ 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? 为什么无法打开www.google.com主页? The rest of the extension works, however its just the "chrome.tabs.create" part that doesn't. 该扩展的其余部分均有效,但是仅“ chrome.tabs.create”部分无效。 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:"." “拒绝执行内联脚本,因为它违反了以下内容安全策略指令:“ 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). Chrome扩展程序不允许抓取不在扩展程序中或未列为资源的脚本(因为该错误有些令人困惑地表示)。 The CSP (content security policy) is something that you can define to change this behavior. 您可以定义CSP(内容安全策略)以更改此行为。 The default would look like this: 默认值如下所示:

"content_security_policy": "script-src 'self' chrome-extension-resource: ; object-src 'self'", “ content_security_policy”:“脚本-src'自我'chrome-extension-resource:;对象-src'自我'”,

You probably want something like this: 您可能想要这样的东西:

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

Stick that line in your manifest.json :-) 将该行粘贴在manifest.json中:-)

More examples can be found here 可以在这里找到更多示例

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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