Further to Can I http poll or use socket.io from a Service Worker on Safari iOS? what is the list of what can and cannot be done in a service worker? The answer referenced above says "You cannot ... have an open connection of any sort to your server" which makes sense, but where is that fact documented and how is the restriction enforced?
For example, are certain browser APIs unavailable to Service Workers? or is there an execution quota which prevents a long running process?
Eg. if my service worker has ...
setInterval (()=>{console.log('foo'), 1000})
... will it throw an exception?, will it run and then fail? is the behaviour browser dependent?
Service workers are specialized JavaScript assets that act as proxies between web browsers and web servers. They aim to improve reliability by providing offline access, as well as boost page performance.
In addition, the reliance on document means that cookies cannot be accessed by service workers which cannot access the document object. The Cookie Store API provides an updated method of managing cookies.
Service workers have a total control over every request made from a website. Since they run in the background, they don't need the webpage to be open. That gives them ability to listen and respond to events such as push messages sent from the server to the browser.
Service workers have mostly been associated with offline support for web applications and for push notifications for re-engaging with users. There are pretty good drop-in wrapper libraries like sw-precache that you use to get such functionality without directly writing any Service Worker code yourself!
Service Workers are only supposed to process attached events. And those are to be registered by some script from the outside. Even delaying the execution is not supported in some cases on Safari - Event.waitUntil(promise).
Once your event queue is empty, your user agent is supposed to decide wether it kills of the service. There is no guarantee that anything from then on is going to get executed.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With