Need help understanding lifespan of service worker context

40 views
Skip to first unread message

Demetrios Tsillas

unread,
Feb 26, 2021, 2:40:06 PMFeb 26
to blink-dev
Hi Folks,

I have a service worker which calls an API I am developing. This API returns a promise but the promise can resolve at some later point in time. It relies on an internal browser function.

This API seems to work fine while my document is active and in a tab, but if I close the tab I never see the promise getting resolved. Even though I am calling RunOrPostTaskOnThread with the appropriate callback. Somehow this promise disappears.

From reading what I can on service worker lifespans and from looking at chrome://serviceworker-internals I am expecting that the service worker should still be able to see this promise resolving.

Here is what internals is telling me:

Scope: https://~~~~.com/~~~/
Registration ID: 41
Navigation preload enabled: false
Navigation preload header length: 4
Active worker:
Installation Status: ACTIVATED
Running Status: STOPPED
Fetch handler existence: EXISTS
Script: https://~~~~.com/~~~/service-worker.js
Version ID: 63
Renderer process ID: 0
Renderer thread ID: -1
DevTools agent route ID: -2
Log:

I am new to service workers so I am wondering what I have misunderstood. Should I be using an event here rather than a promise?

Thanks!!!
-Jim.

Ben Kelly

unread,
Feb 26, 2021, 2:43:59 PMFeb 26
to Demetrios Tsillas, blink-dev
Service workers will shut down unless you are holding it alive with a functional event waitUntil() or respondWith().


So you need to pass your promise to a waitUntil().

--
You received this message because you are subscribed to the Google Groups "blink-dev" group.
To unsubscribe from this group and stop receiving emails from it, send an email to blink-dev+...@chromium.org.
To view this discussion on the web visit https://groups.google.com/a/chromium.org/d/msgid/blink-dev/870b403b-c084-4317-8351-8281f0ee1e85n%40chromium.org.

Demetrios Tsillas

unread,
Feb 27, 2021, 8:38:40 AMFeb 27
to blink-dev, wande...@chromium.org, blink-dev, Demetrios Tsillas
Thank you for the response.

Unfortunately what I am trying to do is a bit different from the intended use of SWs. I'm not trying to hold up the state of the SW. I'm just trying to extend its life after it has become active.

Is there something I can do in the blink code which will have that effect? I already have an API to return the promise so I have access to the ScriptState and service worker context.

I'm not concerned with resource consumption or security at this point.

Ben Kelly

unread,
Mar 1, 2021, 10:36:13 AMMar 1
to Demetrios Tsillas, blink-dev
Reply all
Reply to author
Forward
0 new messages