gpt4 book ai didi

javascript - 无法将 javascript 添加到 chrome 扩展 html

转载 作者:行者123 更新时间:2023-11-29 15:58:53 24 4
gpt4 key购买 nike

我想在 chrome 扩展弹出窗口中添加一些 javascript 代码。我正在使用以下代码:

<!DOCTYPE html>
<html>
<head>
<style>
button {
height: 30px;
width: 30px;
outline: none;
}
</style>
<script type="text/javascript" src="popup.js"></script>
</head>
<body>
<button id="ShowButton"></button>
</body>
</html>

文件 popup.js 与 html 文件位于同一文件夹中。

我收到这个错误:

Refused to execute inline script because it violates the following Content Security Policy directive: "script-src 'self' blob: filesystem: chrome-extension-resource:". Either the 'unsafe-inline' keyword, a hash ('sha256-n39xN31cyZtiXqcqzIa0nbASOdc/O6Jshi15mzpw5oA='), or a nonce ('nonce-...') is required to enable inline execution.

这是我的 popup.js 内容:

chrome.tabs.query({'active': true, 'lastFocusedWindow': true}, function (tabs) {
var url = tabs[0].url;
document.getElementById("ShowButton").value= url;
});

这是 manifest.json:

    {
"manifest_version": 2,
"name": "eRelatorio",
"description": "Extensão para fazer o relatorio de jogo na plataforma S**ore!",
"version": "1.0",
"author": "GoodReferee",
"browser_action": {
"default_title": "Have a good day",
"default_popup": "popup.html"
},
"icons": { "128": "icon.png" },
"chrome_url_overrides" : {
"newtab": "newtab.html"
},
"content_security_policy": "script-src 'self' 'unsafe-eval'; object-src 'self'",
"permissions": ["activeTab","tabs"],
"permissions": [
"https://www.google.com/"
]
}

这是错误图片:

Error Image

最佳答案

尝试将下面的代码添加到 manifest.json

使用不安全内联

 "content_security_policy": "script-src 'self' 'unsafe-inline'; object-src 'self'",

关于javascript - 无法将 javascript 添加到 chrome 扩展 html,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55424837/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com