亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

Chrome 擴展程序政策錯誤:拒絕執行內聯事件處理程序,因為它違反了以下內容安全策略指令

Chrome 擴展程序政策錯誤:拒絕執行內聯事件處理程序,因為它違反了以下內容安全策略指令

慕田峪9158850 2022-09-23 09:48:18
我正在開發一個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"  ]}
查看完整描述

1 回答

?
明月笑刀無情

TA貢獻1828條經驗 獲得超4個贊

我想通了!這是因為我有一個內聯執行...而不是手動在html中執行onclick=“我的函數()”,我只是通過javascript聽它!


這是我更新的代碼:


腳本:


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});

}


document.addEventListener('DOMContentLoaded', function() {

 document.querySelector('button').addEventListener('click', loadSearch, false);

}, false)

網頁:


<html>

<head>

    <title>Tracillion</title>

    <link rel = "stylesheet" type = "text/css" href = "style.css">

    <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">Search</button>

</body>


查看完整回答
反對 回復 2022-09-23
  • 1 回答
  • 0 關注
  • 378 瀏覽
慕課專欄
更多

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號