An example using Service Worker?
See original GitHub issueWhen I saw this I assumed I could slot a service worker in the same place a web worker was being used in the example, but service workers don’t have self.postMessage
, so it doesn’t work. I’ve got it working now by hooking up the proxy through a MessagePort in a message event - is that the best way to do it?
Either way, it would be great to have an example showing the best practise for this.
Issue Analytics
- State:
- Created 6 years ago
- Comments:10 (1 by maintainers)
Top Results From Across the Web
Using Service Workers - Web APIs | MDN
A service worker functions like a proxy server, allowing you to modify requests and responses replacing them with items from its own cache....
Read more >Basic Service Worker Sample - GitHub Pages
This sample demonstrates a basic service worker that could be used as-is, or as a starting point for further customization.
Read more >Service worker overview - Chrome Developers
Service workers are specialized JavaScript assets that act as proxies between web browsers and web servers. They aim to improve reliability by ...
Read more >Service Workers Examples & Interesting Use Cases - Dexecure
In this blog post, learn what service workers are and what can you do with Service Workers with the top 4 examples. Visit...
Read more >Making A Service Worker: A Case Study - Smashing Magazine
This article explains what a service worker is and how to put together your own by registering, installing, and activating it without any ......
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
You are right, a ServiceWorker doesn’t have
self.postMessage
at there might be potentially multiple open windows. So yeah, sending a MessagePort is one good solution. Another option would be to get the actual window object usingself.clients.get()
orself.clients.matchAll()
.It’s probably a good idea for me to write an example for this.
Hope this helps.
I think I like your solution better. I’ll adjust my PR 😃