Persistent Websocket Connection

46 views
Skip to first unread message

Kiddie Development

unread,
Jun 20, 2025, 7:07:35 AMJun 20
to Chromium Extensions
Hi all,

I am making an extension that requires websocket connection to a server. I noticed that on MacOS, the connection goes down (due to power saving I assume). I tried using chrome.power API to keep the system on but it does not work. I also tried pinging, and using chrome.alram but with no luck. There are no issues with Windows machines.

When the machine is idle, I noticed on https://myaccount.google.com/device-activity that the session keep updating ( it shows last activity minutes ago) which means that chrome is connecting to google services. but it seems chrome does not give the same treatment to extensions.

Is there a way to make the extension connection persistent? or make it checks the server  frequently more reliably?

Thank you,

Oliver Dunk

unread,
Jun 20, 2025, 7:24:39 AMJun 20
to Kiddie Development, Chromium Extensions
Hi,

First of all, something to keep in mind is that if you are starting the connection from a service worker, Chrome automatically terminates inactive service workers periodically. This includes service workers with an active WebSocket connection, unless there is activity on those WebSockets. You can learn more about this here: https://developer.chrome.com/docs/extensions/how-to/web-platform/websockets

Assuming that isn't the issue, even if the service worker is alive, it sounds expected that it would disconnect if the device goes to sleep.

You mentioned that you're attempting to use the power API but it isn't working. Is the problem that the device is going to sleep still, or that when you manually put the device to sleep the WebSocket connection is ended?
Oliver Dunk | DevRel, Chrome Extensions | https://developer.chrome.com/ | London, GB


--
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 visit https://groups.google.com/a/chromium.org/d/msgid/chromium-extensions/8304648a-d7d8-491e-896e-811d2d0ee614n%40chromium.org.
Reply all
Reply to author
Forward
0 new messages