javascriptservice-workerservice-worker-events

Service worker - handling errors on the front end


I am looking to handle the error from a service worker in the front end. I saw this question - How to do proper Error Handling using Web Workers?

I tried the onerror - I tried using a post message from the service worker and listen for it on the front end. I tried listening for a on error. I couldn't find a way to get the message in the front end script again.


Solution

  • In the end I found the broadcast channel API. This worked great for sending messages back and fourth

    https://developer.mozilla.org/en-US/docs/Web/API/Broadcast_Channel_API