question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

An example using Service Worker?

See original GitHub issue

When 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:closed
  • Created 6 years ago
  • Comments:10 (1 by maintainers)

github_iconTop GitHub Comments

1reaction
surmacommented, Oct 17, 2017

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 using self.clients.get() or self.clients.matchAll().

It’s probably a good idea for me to write an example for this.

Hope this helps.

0reactions
surmacommented, Jun 15, 2018

I think I like your solution better. I’ll adjust my PR 😃

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found