service_worker console.log is global?

52 views
Skip to first unread message

pchu...@gmail.com

unread,
Dec 15, 2022, 11:03:08 PM12/15/22
to Chromium Extensions
I have a simple extension test, if you put console.log in background.js, and inspect element on popout.html, it's showing logs from background.js. 

Is this expected behavior? I can't find any documentation on this. 

{
"name": "My Extension",
"version": "1.0",
"manifest_version": 3,
"description": "A simple Chrome extension with a popout page and a service worker",
"permissions": [
"activeTab"
],
"action": {
"default_popup": "popout.html"
},
"background": {
"service_worker": "background.js"
}
}

wOxxOm

unread,
Dec 16, 2022, 4:47:04 AM12/16/22
to Chromium Extensions, pchu...@gmail.com
Yes, this is the intended behavior because a web service worker conceptually exists to provide contents of the web page shown to the user via the onfetch hook.

It's problematic though because 99.9% extensions don't use onfetch, actually they don't need any of the special things that service worker offers except one benefit of running in a separate physical thread, but even that is only really helpful in 1% of time when the extension shows a slow UI and listens to frequent chrome events simultaneously. This is just another evidence that choosing the service worker technology was a mistake, but I don't think Chromium team is brave enough to admit it. A better solution would be to simply add the ability to run the MV2 event page in a separate thread by default e.g. via a key in manifest.json (obviously, it would disable getBackgroundPage methods).

You can suggest a feature request in https://crbug.com to hide the messages for extension service worker.

The inconvenient workaround is to enable showing just the selected context in console options and choose the context in console toolbar:
Clip092.png

Another workaround is to prefix the messages with BG: and use it as a filter in console toolbar:
  • BG:
  • -BG:

Jackie Han

unread,
Dec 16, 2022, 5:16:00 AM12/16/22
to wOxxOm, Chromium Extensions, pchu...@gmail.com
If you don't want to see the service worker log. Check the "Selected context only" setting in the console settings.

Screenshot 2022-12-16 at 18.04.42.png
After setting it, logs from service worker or other workers or iframes will be hidden.
When you want to see other context logs, you can switch context manually as below.

Screenshot 2022-12-16 at 18.06.26.png

--
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/e6496708-dbab-464b-a1b4-c8563f3ca877n%40chromium.org.

pchu...@gmail.com

unread,
Dec 16, 2022, 10:02:12 AM12/16/22
to Chromium Extensions, Jackie Han, Chromium Extensions, pchu...@gmail.com, wOxxOm
That solved it, thanks wOxxOm & Jackie!

The chrome extension I am developing is a niche product for business, and generates a lot of new popout windows via chrome api. 
Seems like a a potential resource hog to have every page have service_worker context available with logs. 

Definitely seems like of all the changes to V3, service_worker seems to be the biggest source of frustration.
Any good documentation to read up on to really understand service workers in extensions?
Screen Shot 2022-12-16 at 6.58.43 AM.png
Reply all
Reply to author
Forward
0 new messages