Manifest V3 and Server Sent Events

674 views
Skip to first unread message

Zenitsu

unread,
May 11, 2022, 12:26:15 PM5/11/22
to Chromium Extensions
Is it possible to use SSE?
I know that WebSockets are a no-no for extensions v3, I haven't used SSE before and I'm considering using it for the extension I'm building now

 

Cuyler Stuwe

unread,
May 11, 2022, 12:32:59 PM5/11/22
to Zenitsu, Chromium Extensions
You can definitely use WebSockets in an MV3 browser extension; You just can’t use them in the background service worker.

The problem isn’t that it’s disallowed or anything, but instead that it’s technically-infeasible for something that expects to maintain a persistent connection to maintain that persistent connection within an ephemeral service worker.

On Wed, May 11, 2022 at 9:26 AM Zenitsu <wmore...@gmail.com> wrote:
Is it possible to use SSE?
I know that WebSockets are a no-no for extensions v3, I haven't used SSE before and I'm considering using it for the extension I'm building now

 

--
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/a6d83470-3657-49e7-9f87-4fbac898e5b1n%40chromium.org.

Zenitsu

unread,
May 11, 2022, 12:49:13 PM5/11/22
to Chromium Extensions, salem...@gmail.com, Chromium Extensions, Zenitsu
yeah, I'm aware, it is not feasible in my case because it would have to be in the SW, and the service worker is put to sleep 😴  constantly. There is a list of things that can wake up the service worker, like Chrome Alarms and Web Push. Still, I'm considering SSE instead of Web Push because SSE seems designed for what I want to achieve now, which is to send updates with JSON data from server to client, so it updates the state in the client-side react in several situations. Web Push seems to be primarily designed to display notifications and not carry a JSON payload.

Since I haven't used SSE yet I'm not sure if it would work if I have the event listener in my service worker, I'm not sure if it behaves like web push and would wake up the service worker or not, the documentation on extensions is so limited, I wish we could add contributions to the documentation, but it doesn't seem possible according to this GH issue https://github.com/GoogleChrome/developer.chrome.com/issues/2652

in any case, any insights in regards to using SSE with an extension V3 background (service-worker) is much appreciated! 

hrg...@gmail.com

unread,
May 11, 2022, 6:54:18 PM5/11/22
to Chromium Extensions, Zenitsu, salem...@gmail.com, Chromium Extensions
Take a look at this post from Simeon:

In particular, this paragraph (emphasis mine):
"The current plan is that offscreen documents will live as long as necessary to fulfil their purpose*. For example, an episode of a podcast can be over an hour long, so a podcast client extension would need to have a long lived (but not necessarily persistent) page context to play that audio file. In this scenario it's conceivable that an offscreen document will stay alive for multiple hours. Scripting a page loaded in the background (I hesitate to call that scraping, but I digress) is another case where an offscreen document may end up living for an extended period."

Apparently, the new offscreen documents will have a much longer life-time than the service worker has. I presume this will depend on the "reason" you give when creating the offscreen document. Also, this "reason" will probably be enforced by policy during the review process.
So, if the list of valid reasons for creating an offscreen document includes your use case, you could use that to create a WebSocket that lives for much longer than the service worker.

But of course, if this new functionality is not implemented before MV2 is dead, then it'll be useless as every developer would've had to solve their problems in a different way already.
Reply all
Reply to author
Forward
0 new messages