Chrome v103+出现WebAssembly编译错误,Rust Wasm开发扩展求助
解决Chrome扩展中Wasm代码生成被禁止的问题
Chrome v102及以上版本收紧了扩展内WebAssembly的运行权限,默认限制Wasm代码生成,这就是你遇到CompileError: WebAssembly.instantiateStreaming(): Wasm code generation disallowed by embedder错误的原因。
以下是具体解决方案:
修改扩展的
manifest.json,根据Manifest版本添加对应权限:- 若使用Manifest V3,在
content_security_policy的extension_pages中加入'wasm-unsafe-eval':{ "manifest_version": 3, "content_security_policy": { "extension_pages": "script-src 'self' 'wasm-unsafe-eval'; object-src 'self';" }, // 其他扩展配置项 } - 若使用Manifest V2,直接调整
content_security_policy字段:{ "manifest_version": 2, "content_security_policy": "script-src 'self' 'wasm-unsafe-eval'; object-src 'self';", // 其他扩展配置项 }
- 若使用Manifest V3,在
保持Wasm文件的合规加载:不要用
eval或动态生成Wasm代码的方式,继续使用WebAssembly.instantiateStreaming直接加载本地Wasm文件,避免跨域加载。重新加载扩展并测试:修改配置后,在Chrome扩展管理页面重新加载扩展,验证v103+版本下Wasm是否正常运行。
内容的提问来源于stack exchange,提问作者Feelix343
相关产品推荐
相关产品推荐

