This commit is contained in:
Nicolas Lepage 2021-01-22 15:25:41 +01:00
parent 574bb8928c
commit 078ff3547e
No known key found for this signature in database
GPG Key ID: B0879E35E66D8F6F
2 changed files with 1 additions and 16 deletions

View File

@ -1,15 +0,0 @@
window.wasmhttp = {
register: async (wasm, { scope, base = '', swUrl = 'sw.js', args = [] } = {}) => {
const options = {}
if (scope) options.scope = scope
// FIXME register once (beware of changing scope ?)
const registration = await navigator.serviceWorker.register(swUrl, options)
await navigator.serviceWorker.ready
registration.active.postMessage({
type: 'wasmhttp.register',
wasm,
base,
args,
})
}
}

2
sw.js
View File

@ -1,6 +1,6 @@
importScripts('https://cdn.jsdelivr.net/gh/golang/go@go1.15.7/misc/wasm/wasm_exec.js')
function registerWasmHTTPListener(wasm, base, args = []) {
function registerWasmHTTPListener(wasm, { base, args = [] } = {}) {
let path = new URL(registration.scope).pathname
if (base && base !== '') path = `${trimEnd(path, '/')}/${trimStart(base, '/')}`