问题
chrome 升级到130.0.6723.59后,之前工作正常的插件遇到了CSP(Content Security Policy)限制问题
报错日志:
Refused to load the script 'chrome-extension://***.js' because it violates the following
Content Security Policy directive: "script-src 'self' 'wasm-unsafe-eval' 'inline-speculation-rules'".
Note that 'script-src-elem' was not explicitly set, so 'script-src' is used as a fallback.
日志中错误堆栈跟踪到编译后的文件
(async () => {
await import(
/* @vite-ignore */
chrome.runtime.getURL("assets/index.tsx-52c4f978.js")
);
})().catch(console.error);
})();
解决办法
第一步
# 临时先直接修改编译后的文件,重新打个包先提审,后面再找更合理的解决办法
# 直接修改/dist/assts/*-loader*.js文件
(async () => {
await import("./index.tsx-52c4f978.js");
})().catch(console.error);
})();
第二步
# 改完后开发者模式直接测试,后台没问题,前台依然有问题
Refused to load the script 'chrome-extension://***/assets/index.tsx-***.js'
because it violates the following Content Security Policy directive:
"script-src 'self' 'wasm-unsafe-eval' 'inline-speculation-rules'".
Note that 'script-src-elem' was not explicitly set, so 'script-src' is used as a fallback.
#修改manifest.json
web_accessible_resources[0].resources下,再增加一个"assets/*.js"
重新编译,再修改第一步里的loader*.js,测试没问题
打包,提审。