wasm-http-server/index.js
2020-12-24 12:38:29 +01:00

16 lines
461 B
JavaScript

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,
})
}
}