我正在开发一个chrome扩展来完成一个简单的任务,除了我花了大部分时间在一行html代码上,以弄清楚如何正确地赋予它正确的权限,我试图这样做,但我不知道实际放什么。
我在尝试运行 java 脚本时遇到的错误:
拒绝执行内联事件处理程序,因为它违反了以下内容安全策略指令:“script-src 'self' https://apis.google.com”。启用内联执行需要“不安全内联”关键字、哈希(“sha256-...”)或随机数(“nonce-...”)。
这就是我试图修复策略错误的原因:
<meta http-equiv = "Content-Security-Policy" content="script-src 'self' data: https://apis.google.com 'unsafe-inline' 'sha256-base64EncodedHash'">
我尝试将内容安全策略放在清单文件中,并尝试在上面的代码中加入其他内容。
我所有的代码(我知道我不应该这样做,但我不知道是什么导致了这个问题):
网页:
<html>
<head>
<title>Tracillion</title>
<link rel = "stylesheet" type = "text/css" href = "style.css">
<meta http-equiv = "Content-Security-Policy" content="script-src 'self' data: https://apis.google.com 'unsafe-inline' 'sha256-base64EncodedHash'">
<script type = "text/javascript" src = "popup.js"></script>
</head>
<body>
<h1 class = "header">Enter what you would like to search!</h1>
<div class = "line"></div>
<input class = "input" id = "input">
<button type = "submit" class = "button" onclick="loadSearch()">Search</button>
</body>
脚本:
function loadSearch() {
var inputResult = document.getElementById("input").value;
var final = 'https://www.google.com/search?q=' + encodeURI(inputResult + ' site:v3rmillion.net');
chrome.tabs.create({url: final});}
清单:
{
"name": "bruh",
"description": "bruh moment",
"version": "1.0",
"background": {
"scripts": [
"popup.js"
]
},
"manifest_version": 2,
"browser_action": {
"default_icon": "icon.png",
"default_popup": "popup.html"
},
"permissions": [
"tabs"
]
}
明月笑刀无情
相关分类