MV3 issue sending stateless message to content script from service worker

121 views
Skip to first unread message

Dennis Park

unread,
Apr 9, 2021, 11:50:03 AM4/9/21
to Chromium Extensions
Hi, I am currently developing a new extension, and have decided to update from MV2 to MV3. Previously, I had a simple background script (see below) that would simply add some event listeners for browserActions (updated to action) and commands, that would then send a message to chrome.tabs for my content script to intercept. However, when registered as a service worker in MV3, these stateless event listeners no longer seem to work... what am I doing wrong?
541687f216113edb6eb42b75c7356614.png
a28ab368b666f65d12b1465b7105c836.png
2a36e03607f7b09617894d385fa8afc1.png
45a8c3ae6d60041d22ea59da8c7e8ae4.png

Matthew Podolak

unread,
Apr 9, 2021, 12:56:17 PM4/9/21
to Chromium Extensions, denni...@gmail.com
If you have a default popup set in the manifest /a popup is created, an event will not be created.

From the docs for actionListener: "Fired when an action icon is clicked. This event will not fire if the action has a popup."

Dennis Park

unread,
Apr 9, 2021, 2:34:25 PM4/9/21
to Chromium Extensions, mpod...@gmail.com, Dennis Park
actionns.png
I have no default_popup defined in my manifest, nor any calls to action.setPopup()... my full app manifest:
manifest.json

Dennis Park

unread,
Apr 9, 2021, 3:15:24 PM4/9/21
to Chromium Extensions, mpod...@gmail.com
as it turns out, I'm blind and forgetful. my project setup had been unregistering service workers
image.png

Matthew Podolak

unread,
Apr 9, 2021, 5:13:26 PM4/9/21
to Chromium Extensions, denni...@gmail.com, Matthew Podolak
Glad you were able to resolve it!

Simeon Vincent

unread,
Apr 9, 2021, 5:37:38 PM4/9/21
to Matthew Podolak, Chromium Extensions, denni...@gmail.com
Dennis, you shouldn't need to do any SW registration or updating. Chrome transparently handles that for you.

Were you using a service worker in the MV2 version of your extension?

Simeon - @dotproto
Chrome Extensions DevRel


--
You received this message because you are subscribed to the Google Groups "Chromium Extensions" group.
To unsubscribe from this group and stop receiving emails from it, send an email to chromium-extens...@chromium.org.
To view this discussion on the web visit https://groups.google.com/a/chromium.org/d/msgid/chromium-extensions/82834622-bd2d-404e-aa92-cf887d223269n%40chromium.org.

wOxxOm

unread,
Apr 10, 2021, 9:04:29 AM4/10/21
to Chromium Extensions, Simeon Vincent, Chromium Extensions, denni...@gmail.com, mpod...@gmail.com
This is probably tenth time I see people trying to register a service worker manually in an extension so it might make sense to add a big warning in the documentation telling people not to do it. Both in the migration guide and in the article about the service worker.

Simeon Vincent

unread,
Apr 14, 2021, 5:22:33 AM4/14/21
to Chromium Extensions, wOxxOm, Simeon Vincent, Chromium Extensions, denni...@gmail.com, mpod...@gmail.com
Thanks for the suggestion, wOxxOm. I'm adding it to the docs backlog now. 

Simeon - @dotproto
Chrome Extensions DevRel

Reply all
Reply to author
Forward
0 new messages