Offscreen document reason: web workers?

444 views
Skip to first unread message

Tyler Carson

unread,
Dec 13, 2022, 4:36:38 PM12/13/22
to Chromium Extensions
I'm getting a runtime error using the new offscreen document API in Chrome 109 beta using our initial code to test it, with the reason set to TESTING.

Our use case (web workers) doesn't appear in the options to choose from. What would be the recommended reason to specify in this case, or how would we go about adding workers to the list of reasons?

Also wondering under what conditions the "justification" string would be presented to the user.

wOxxOm

unread,
Dec 13, 2022, 4:56:27 PM12/13/22
to Chromium Extensions, ty...@keepersecurity.com
  1. `testing` is only available behind a command line switch now: --offscreen-document-testing
  2. no such reason yet, see https://crbug.com/1339382#c52, they'll probably add it later, meanwhile use the most suitable/neutral one
  3. as the documentation says `justification` may be displayed to the user - currently this is not implemented.

Tyler Carson

unread,
Dec 13, 2022, 5:06:43 PM12/13/22
to wOxxOm, Chromium Extensions
Okay great to see it's likely to be added as an option in the future. Will choose a suitable one to use in the meantime.

Thanks for pointing me in the right direction!
--

Tyler Carson | Senior Software Engineer


Uladzimir Yankovich

unread,
Dec 14, 2022, 9:09:42 AM12/14/22
to Chromium Extensions, ty...@keepersecurity.com, Chromium Extensions, wOxxOm
Colleagues, I understand correctly: вy creating a web worker in an Offscreen document, we can use sockets to synchronize our extensions in real-time. How good is this practice? Or I'm wrong?

I wonder if we can call Firebase authorization in this web worker?

wOxxOm

unread,
Dec 14, 2022, 9:14:13 AM12/14/22
to Chromium Extensions, yank...@manganum.app, ty...@keepersecurity.com, Chromium Extensions, wOxxOm
You can do it anywhere because WebSocket is defined in workers, but the problem is the limited lifetime of the offscreen document. When you specify a reason there will be an automatic detection of inactivity e.g. for audio it's silence, I don't know how they plan to limit it for other reasons as the whole idea of enforcing the lifetime limits artificially is not based on real needs of the extension platform.

Simeon Vincent

unread,
Dec 15, 2022, 12:04:29 AM12/15/22
to wOxxOm, Chromium Extensions, yank...@manganum.app, ty...@keepersecurity.com
Also wondering under what conditions the "justification" string would be presented to the user.

As wOxxOm said, the justification string isn't currently used. The basic idea is that the browser can show the justification to the user if it detects that the offscreen document has been alive for an unusually long time. Unfortunately I can't get more specific than that because designs for offscreen document lifetime interventions are still in flux.

Colleagues, I understand correctly: вy creating a web worker in an Offscreen document, we can use sockets to synchronize our extensions in real-time. How good is this practice? Or I'm wrong

I wonder if we can call Firebase authorization in this web worker?

With regard to the general question about WebSockets in offscreen documents, WebSockets aren't a supported use for the Offscreen API and (IMO) are very unlikely to be. That said, we are planning to relax extension service worker lifetime constraints so that will no longer be terminated after a fixed amount of time.

For clarity, offscreen documents are not web workers, they're pages. 

As for the question about Firebase auth, I think the right course here might be to combine an offscreen document (probably with "IFRAME_SCRIPTING" as the reason) with a sandboxed page to handle the script execution. I may be confusing my libraries, but as I recall Firebase Auth tries to append remote scripts to the page it's running on. MV3's remotely hosted code restrictions don't allow arbitrary script execution on extension origins, but we do allow script evaluation in sandboxed pages. 

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/e209cd84-f673-43a6-ae21-a6452412be4dn%40chromium.org.

JM Lambert addeective

unread,
Feb 5, 2023, 2:44:24 AM2/5/23
to Chromium Extensions, Simeon Vincent, Chromium Extensions, yank...@manganum.app, ty...@keepersecurity.com, wOxxOm
Actually I am moving a V2 extension using web sockets from the background script and working very well.
I moved the code to  service worker (and V3) and despite the fact I have no 0 errors in the console, the socket never gets connected...
Am I doing something wrong ?

manifestV3:
"host_permissions": [
],

Code is simple:
    let socket = io("https://flow-api-socket.app);

=> I don't see the network request in devtools which I see with V2:
https://flow-api-socket.app/socket.io/?EIO=4&transport=polling&t=OOWXRxc

PS/ I moved the same code in offscreen document and it works as a charm.

any help really appreciated!
Reply all
Reply to author
Forward
0 new messages