Skip to content

Commit a0f47da

Browse files
committed
Wasm loaded in background script
1 parent 5ecb032 commit a0f47da

File tree

3 files changed

+9
-1
lines changed

3 files changed

+9
-1
lines changed

manifest.json

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,5 +36,9 @@
3636
"background": {
3737
"service_worker": "src/chrome/background.ts",
3838
"type": "module"
39+
},
40+
"content_security_policy": {
41+
"extension_pages": "script-src 'self' 'wasm-unsafe-eval'; object-src 'self';",
42+
"sandbox": "sandbox allow-scripts allow-forms allow-popups allow-modals; script-src 'self' 'unsafe-inline' 'unsafe-eval'; child-src 'self';"
3943
}
4044
}

package.json

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,8 @@
3636
},
3737
"scripts": {
3838
"start": "vite",
39+
"install:rust": "curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh",
40+
"install:wasm": "curl https://rustwasm.github.io/wasm-pack/installer/init.sh -sSf | sh",
3941
"build:wasm:dev": "(cd src/wasm-lib && wasm-pack build --dev --target web --out-dir pkg) && cp src/wasm-lib/pkg/wasm_lib_bg.wasm public",
4042
"build:wasm": "(cd src/wasm-lib && wasm-pack build --target web --out-dir pkg) && cp src/wasm-lib/pkg/wasm_lib_bg.wasm public",
4143
"build": "vite build",

src/chrome/background.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,9 @@ async function initialiseWasm() {
6565
const fullUrl = '/wasm_lib_bg.wasm'
6666
const input = await fetch(fullUrl)
6767
const buffer = await input.arrayBuffer()
68-
return await init(buffer)
68+
const output = await init(buffer)
69+
console.log('Wasm loaded: ', output)
70+
return output
6971
} catch (e) {
7072
console.log('Error initialising WASM', e)
7173
throw e

0 commit comments

Comments
 (0)