-
Install wasm-pack:
cargo install wasm-pack
-
Go to
/wasm_mod
and runbuild.bat
.
It will compile the.wasm
module and.js
-wrapper for it and put them in theextension/js/wasm
-
Go to Chrome extensions page and load unpacked extension from
/extension
extension/js/content.js
demonstrates how to load wasm into the content script
Important: in the content script, the module can only be loaded for those sites whose Content Security Policy does not prohibit itextension/js/background.js
demonstrates how to load wasm into the background worker script- For
wasm-pack
always use--target web
manifest.json
:- To load the wasm module into the content script, you should list
.wasm
and corresponding.js
in theweb_accessible_resources.resources
section of manifest - To load the wasm module into the background worker script, you should specify
wasm-unsafe-eval
in thecontent_security_policy.extension_pages
section of manifest
- To load the wasm module into the content script, you should list
- Chrome 114 (extension manifest v3)
- Rust 1.70 (edition 2021)
- wasm-bindgen 0.2.86
- wasm-pack 0.11.1