0

I'm writing a web extension for Chrome and I'm using a service worker to do some background activities (something that with manifest V2 would have been done using a BackgroundScript). As many sources suggest, in this case instead of manually creating a service worker you can (and maybe should? I ran into issues trying to spawn it manually) declare it inside your manifest and the service worker will be created automatically. It works, but now my problem is: how do I send a message to it? Usually you would create a worker manually and then send a message like this:

let worker=new Worker("some-script.js")
worker.postMessage(some_message)

But I can't use this method as I don't have any worker object that I can reference. How can I send a message to a worker declared inside the manifest?

PS: I need to send a message from a script that gets injected inside a webpage, so chrome.runtime.sendMessage doesn't work.

GTP95
  • 13
  • 2

0 Answers0