7

Our webapp registers a service worker. We also have a Chrome extension. What we need is to send messages from service worker to the extension without having the webapp open. What is the right approach to do that?

Our current solution is requesting some URL in the service worker and capturing it in the extension's background script using webRequest - chrome.webRequest.onBeforeRequest.addListener. It works but it looks pretty much nonstandardly.

Martin Ždila
  • 2,998
  • 3
  • 31
  • 35
  • 1
    Alas, not yet: https://crbug.com/452942 and https://crbug.com/545535 – wOxxOm Sep 23 '16 at 14:37
  • Martin, I need to do the same. Could you post some example code of your solution? – Michael Updike Feb 18 '17 at 01:58
  • 2
    @MichaelUpdike https://gist.github.com/zdila/ba6c0c1e0be5caafbc1d5bb4832f7d75 – Martin Ždila Feb 20 '17 at 09:55
  • Hi, is there any new solution? I would like to send data from firebase-messaging-sw.js to manifest v3 service worker in order to set badge text. Normal service worker don't have set badge text API available. – Joseph Jan 02 '22 at 10:06
  • Any update on this? https://bugs.chromium.org/p/chromium/issues/detail?id=452942 is closed without any resolution. – azizj Dec 08 '22 at 14:58

1 Answers1

2

(from wOxxOm's comment, since he hates answering anywhere but in comments)

Your solution is as good as any - before more straightforward support is added, as per this feature request.

Xan
  • 74,770
  • 16
  • 179
  • 206