Is the communication with content script stuck/ not happen at all due to the service worker being inactive?

174 views
Skip to first unread message

Jaliya roshen Jayarathne

unread,
Aug 26, 2022, 7:35:31 AM8/26/22
to Chromium Extensions
One of the major changes with transition to MV 3 of the chrome extension manifest  is the introduction of the service worker. Therefore, in the absence of interaction between scripts, this become inactive as follows. What are the disadvatanges of this service worker due to this?. I have seen some extensions stuck and popUps are not working as expected beacuse of this inactive state. That means manually we have to active the service worker. Is there any workaround for this?
inactive.png

T S

unread,
Aug 30, 2022, 4:26:39 AM8/30/22
to Chromium Extensions, jaliya...@gmail.com
Locally, this shouldn't matter too much - the service worker will wake up if a content script sends a message or starts a connection, or any other event occurs for which it has a listener.
However, if you're hoping to do any persistent background work, the outlook is bleak.  It sounds like the current behaviour is a 5 minute hard timeout, with a caveat for native messaging?  Of course, this behaviour isn't documented anywhere, so I could be very wrong.
I really hope this gets reconsidered.  For all the manifesto's focus on capability, this dramatically shrinks the value that extensions can provide.

Jói Sigurdsson

unread,
Aug 30, 2022, 10:50:36 AM8/30/22
to Chromium Extensions, T S, jaliya...@gmail.com
> the service worker will wake up if a content script sends a message or starts a connection,
> or any other event occurs for which it has a listener.

A bit of a caveat, it should wake up, but it will only wake up if your user is not bitten by the (fairly common) bug https://bugs.chromium.org/p/chromium/issues/detail?id=1271154

Let's hope Google fixes that issue well in time for the January MV3 deadline.

Cheers,
Jói

T S

unread,
Aug 31, 2022, 1:38:08 PM8/31/22
to Chromium Extensions, j...@crankwheel.com, T S, jaliya...@gmail.com
Fair point.

Having done a little testing, it certainly SEEMS like a service worker with e.g. an open websocket will remain open indefinitely now - but I'm guessing this behavior definitely isn't guaranteed.
It looks like chromium is converging on offscreen documents to handle some of the previous usecases for background scripts, but as these will still have limited lifetimes, they could still be unwieldy.

wOxxOm

unread,
Sep 1, 2022, 12:15:30 PM9/1/22
to Chromium Extensions, T S, j...@crankwheel.com, jaliya...@gmail.com
Judging by the source code, only nativeMessaging keeps the worker running forever, so maybe you had devtools open for the worker. It freezes the kill timer.

T S

unread,
Sep 2, 2022, 6:49:33 AM9/2/22
to Chromium Extensions, wOxxOm, T S, j...@crankwheel.com, jaliya...@gmail.com
Yeah, you're right, I must have had devtools still attached without realising.  That's a shame, I really don't want to have to be dependent on foreground tabs or injected keepalives but it sounds like it's unavoidable.


Reply all
Reply to author
Forward
0 new messages