Skip to content

Service worker example: stops working when SW is suspended #637

@rejhgadellaa

Description

@rejhgadellaa

I've built a simple Notification API tester web app to do some debugging on what iOS Safari 16.4 does and does not support, and figured I could use Comlink to communicate between the main thread and the service worker.

I based my code on the service worker example, but found that, on Android at least, it stops working after a while when I put the page in the background and then come back to it.

I think I found the problem: the browser is free to suspend / completely kill the SW ifi it's not in use. That means it throws away everything: the port, Comlink, bathwater, baby, tub, etcetera.

I'm not sure if there is a (good) solution that doesn't require Comlink to support Client.postMessage(), because that's the one thing that will spin up the SW?

I'm currently trying some workarounds, like checking if the SW and Comlink is still alive, etc, but I fear that needs to happen with every call:

  • I think the SW can even be killed when the page is in the foreground?
  • The SW might've been killed, spun up for some other reason - so without Comlink setup, then killed again. Even if the SW is alive, Comlink may still need to be initiated.

Will report back.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions