mirror of
https://github.com/nlepage/go-wasm-http-server.git
synced 2025-03-10 17:29:10 +00:00
16 lines
461 B
JavaScript
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,
|
|
})
|
|
}
|
|
}
|