This recipe shows how to use WASM in Manifest V3.
To load WASM in Manifest V3, we need to use the wasm-unsafe-eval
CSP directive (Content Security Policy).
- Clone this repository.
- Load this directory in Chrome as an unpacked extension.
- Find the extension named "WASM Load Example - Helloworld" and inspect the service worker.
You will see the following output:
[from wasm] Inited.
[from wasm] Hello World!
[from wasm] Hello John
We have already built the WASM file for you. If you want to build it yourself, follow the steps below.
-
Install Rust.
-
Install wasm-pack.
cargo install wasm-pack
-
Build WASM.
cd wasm wasm-pack build --target web
- To import the script generated by
wasm-pack
, we need to declare the service worker as an ES Module.
// manifest.json
...
"background": {
"service_worker": "background.js",
+ "type": "module"
},
...