我有一个执行以下操作的chrome扩展程序,尝试向Google chrome存储添加链接,以便我可以获取该链接,并将其添加到我的html中。在进行调试时,我注意到单击按钮添加链接时,其href为javascript:getStorage
。
完整HTML
<!DOCTYPE html>
<html>
<head>
<title>Open URL</title>
<link rel="stylesheet" href="styles.css">
</head>
<body style="width: 128px; height: 128px;">
<h2><b>Open URL</b></h2>
<h3><a href="javascript:setStorage()" target="_blank">Add Link<br></a></h3>
<h3><a href="https://www.ph4.org/r.php" target="_blank">Random<br></a></h3>
</body>
</html>
错误
Refused to run the JavaScript URL because it violates the following Content Security Policy directive: "script-src 'self' blob: filesystem:". Either the 'unsafe-inline' keyword, a hash ('sha256-...'), or a nonce ('nonce-...') is required to enable inline execution.
清单
{
"manifest_version": 2,
"web_accessible_resources": [
"popup.html", "popup.js"
],
"name": "UrlManager",
"description": "Quickly open urls.",
"version": "1.0.1",
"content_scripts": [
{
"matches": ["<all_urls>"],
"js": ["popup.js"]
}
],
"permissions": [
"tabs",
"storage",
"unlimitedStorage"
],
"browser_action": {
"default_icon": "icon.png",
"default_popup": "popup.html",
"default_title": "Open a URL"
}
}
JS
var storage = chrome.storage.local;
function setStorage() {
var value = prompt("Whats your link")
storage.set({key: value}, function() {
console.log('Value is set to ' + value);
});
}
function getStorage() {
storage.get(['key'], function(result) {
console.log('Value currently is ' + result.key);
});
}
反正有解决此问题的方法吗?