Chrome 擴展程式 V3:拒絕加載腳本“https://translate.google.com/translate_a/element.js?cb=googleTranslateElementInit”,因為它違反了以下內容安全策略指令:“script-src 'self'”。請注意,'script-src-elem' 沒有明確設定,因此 'script-src' 用作后備。
- 我想添加谷歌翻譯來翻譯彈出擴展,但我得到了那個錯誤
我的 html
<!DOCTYPE html>
<html lang="en-US">
<body>
<h1>My Web Page</h1>
<p>Hello everybody!</p>
<p>Translate this page:</p>
<div id="google_translate_element"></div>
<script type="text/javascript">
function googleTranslateElementInit() {
new google.translate.TranslateElement({pageLanguage: 'en'}, 'google_translate_element');
}
</script>
<script type="text/javascript" src="//translate.google.com/translate_a/element.js?cb=googleTranslateElementInit"></script>
</body>
</html>
錯誤
https://user-images.githubusercontent.com/78076796/201490254-8194ba99-2238-462f-843c-8f45be54b68d.png
對于 chrome 擴展程式 v3,我真的找不到任何有關此錯誤的示例。請幫幫我:((
我試圖找到 extension_pages 和沙箱;但它總是失敗
uj5u.com熱心網友回復:
清單 V2
在帶有 manifest V2 的 Chrome 擴展中,您可以這樣做:
清單.json
"content_security_policy": "script-src 'self' https://translate.google.com;
清單 V3
遠程托管代碼
在 Manifest V3 中,所有擴展的邏輯都必須與擴展捆綁在一起。您不能再加載和執行遠程托管檔案。根據您的用例和遠程托管的原因,可以使用許多替代方法。
來源:https ://developer.chrome.com/docs/extensions/mv3/intro/mv3-migration/#remotely-hosted-code
轉載請註明出處,本文鏈接:https://www.uj5u.com/yidong/533124.html
