My serviceworker is partially generated by gulp, so there’s some chance it ends up with a SyntaxError or TypeError if I’ve made a mistake, and I’d like to be about to detect in my navigator.serviceWorker.register
code that this has occurred, and send an error report.
I haven’t figured out how to do this. I figured there’d be some sort of “on fail” event but I haven’t found one. It looks like maybe I’m looking for an SW with a redundant
state…
I tried
const newWorker = reg.installing
newWorker.addEventListener('statechange', () => {
if (newWorker.state == 'redundant') {
// log error
}
})
but the condition doesn’t seem to fire. This condition also doesn’t fire:
reg.addEventListener('updatefound', () => {
if (reg.redundant) {
// log error
}
})
I don’t see any examples in the SW tutorials of this, which is surprising since it seems like a sort of basic thing to want to notice and detect.