wasm-http-server/index.js

16 lines
460 B
JavaScript
Raw Normal View History

2019-12-02 16:52:40 +01:00
window.wasmhttp = {
2020-06-14 15:34:58 +02:00
register: async (wasm, { scope, base = '', swUrl = 'sw.js', args = [] } = {}) => {
2019-12-02 16:52:40 +01:00
const options = {}
if (scope) options.scope = scope
2020-06-14 15:26:42 +02:00
//FIXME register once (beware of changing scope ?)
2019-12-02 16:58:20 +01:00
const registration = await navigator.serviceWorker.register(swUrl, options)
2019-12-02 16:52:40 +01:00
await navigator.serviceWorker.ready
registration.active.postMessage({
type: 'wasmhttp.register',
wasm,
base,
2020-06-14 15:34:58 +02:00
args,
2019-12-02 16:52:40 +01:00
})
}
}