【发布时间】:2022-12-16 18:21:56
【问题描述】:
当我部署一个使用 firebase 作为 chrome 扩展的 flutter 应用程序时,出现以下错误
main.dart.js:36994 Refused to execute inline script because it violates the following Content Security Policy directive: "script-src 'self'". Either the 'unsafe-inline' keyword, a hash ('sha256-YBHx8OpTDOL4+BciDWDJCan2nXW4/AjhyYodJv5SvZg='), or a nonce ('nonce-...') is required to enable inline execution.
我试过像这样添加 engine.js 但没有用。
window.ff_trigger_firebase_core = async (callback) => {
callback(await import("https://www.gstatic.com/firebasejs/9.11.0/firebase-app.js"));
};
window.ff_trigger_firebase_app_check = async (callback) => {
callback(await import("https://www.gstatic.com/firebasejs/9.11.0/firebase-app-check.js"));
};
window.ff_trigger_firebase_remote_config = async (callback) => {
callback(await import("https://www.gstatic.com/firebasejs/9.11.0/firebase-remote-config.js"));
};
window.ff_trigger_firebase_firestore = async (callback) => {
callback(await import("https://www.gstatic.com/firebasejs/9.11.0/firebase-firestore.js"));
};
然后情况变得更糟,上面的错误仍然存在,加上新的错误:
engine2.js:22 Uncaught (in promise) TypeError: Failed to fetch dynamically imported module: https://www.gstatic.com/firebasejs/9.11.0/firebase-remote-config.js
Refused to load the script 'https://www.gstatic.com/firebasejs/9.11.0/firebase-firestore.js' because it violates the following Content Security Policy directive: "script-src 'self' 'wasm-unsafe-eval'". Note that 'script-src-elem' was not explicitly set, so 'script-src' is used as a fallback.
(其中很多)
然后我尝试更改manifest.json中的CSP
"content_security_policy": {
"extension_pages": "script-src 'self' https://www.gstatic.com; object-src 'self'"
},
但现在更糟糕的是,扩展完全拒绝加载并在重启 chrome 后自行卸载:
Failed to load extension
File
~/StudioProjects/yilong_ma/build/web
Error
'content_security_policy.extension_pages': Insecure CSP value "https://www.gstatic.com" in directive 'script-src'.
Could not load manifest.
【问题讨论】:
标签: javascript flutter firebase dart google-chrome-extension