Hello,
Is there a way to prompt the side panel to reconnect to the service worker using `chrome.runtime.connect`?
I'm using Comlink for remote procedure calls between different extension contexts (webpage, content script in iframe, side panel, service worker; see diagram below). The side panel is responsible for initiating the connection to the service worker, but this breaks when the service worker goes to sleep.
If the side panel is open but inactive, the connection isn't re-established when the service worker wakes up. Since the service worker can't trigger the side panel, RPC calls to the panel fail until the user interacts with it again.
This wasn’t an issue with a popup, which I could message to reconnect. But with the side panel, there's no way to trigger that reconnection externally.
This causes issues in my tab and bookmark manager: for example, new tabs don’t show up in the side panel if the service worker has slept, whereas they do if the service worker has not slept, or the user has interacted with the side panel (triggering a reconnection).
Since the service worker can go to sleep every ~30 seconds, I cannot realistically ask users to interact with the side panel every it does.
Is there a workaround or recommended pattern for this?
Thanks in advance!
+-----------------------------+
| Extension Page (UI) |
|-----------------------------|
| - Hosts iframe (Web App) |<------------------------+
| | |
| | |
+-----------------------------+ |
^ |
| |
| |
v v
+-----------------------------+ +-----------------------------+
| Web App (in iframe) | | Extension Service Worker |
|-----------------------------| |-----------------------------|
| - Origin:
app.mywebsite.com | | - Access to browser APIs |
| | | |
| | +-----------------------------+
+-----------------------------+ ^
^ |
| |
| |
v |
+-----------------------------+ |
| Content Script (in iframe) |<------------------------+
|-----------------------------|
| - Injected into Web App |
| - Access to browser APIs |
+-----------------------------+