javascript - 当我尝试单击功能时,Chrome 扩展程序出错
问题描述
我有一个 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);
});
}
有没有什么办法解决这一问题?
解决方案
推荐阅读
- shell - 如何显示所有同名文件的日期?
- php - 如何在一段时间内停止所有当前用户的数据库输入
- reactjs - 如何使用反应钩子在全局状态的叶值更改时有条件地渲染组件
- kubernetes - 手动替换一个 pod 上的图像,而其他 pod 使用主图像
- flutter - RenderBox 未布置:RenderRepaintBoundary
- ios - 在 iOS 14 中更改 UITableViewCell 的背景颜色
- android - 横向 - 如何保留数据和布局属性?
- excel - excel格式生成日期(非硬编码日期)
- bash - 用于删除旧备份文件的现有 bash 脚本 - 它是如何工作的?
- spring - 如何使用spring在mongodb中插入一个对象