Skip to Content
Platform.Ontology

Service worker lifetime

A background script registered by a site that persists after the tab is closed.

Works without askingNotifications and backgroundAfter leavingWeb browsersAfter you leave the siteWhile you use it

In one line

Can keep a background helper script for a site that stays after you close the tab

A background script registered by a site that persists after the tab is closed.

It can intercept every request, serve cached content, and wake for push or sync even when no page is open. The browser stops it after about 30 seconds idle, but the registration stays until cleared. Safari deletes it after 7 days of non use.

What it can and can't do

What the user does: Nothing. It is set up the first time you visit a site that uses one

It can

  • Intercept the site's own requests and serve saved copies
  • Wake for push or sync when you allow them
  • Keep the helper registered until you clear it or the site removes it
  • Make a site load fast and work offline

It cannot

  • See other sites' requests or data, since it is limited to the one site
  • Stay running, as the browser stops it after about 30 seconds idle
  • Last in Safari beyond 7 days without a visit
  • Survive when you clear that site's data

How it differs between platforms: Safari deletes a site's helper after 7 days without use. Chrome, Edge and Firefox keep it until cleared.

Browser support

BrowserStatusFirst versionReleasedNote
ChromeSupported402015-01-21None
EdgeSupported172018-04-30None
FirefoxSupported442016-01-26None
SafariSupported11.12018-04-12None
Safari on iPhoneSupported11.32018-03-29None
Chrome on AndroidSupported402015-01-21None
Samsung InternetSupported4.02016-03-11None

How a site asks for it

APInavigator.serviceWorker.register(url)
Browser compat keysapi.ServiceWorkerContainer.register
How access is grantednone
What the user seesNone
Needs a secure context (HTTPS)Yes
Needs a user gestureNo
How long it lastsRegistration persists with no fixed expiry. Script checked for update at most every 24 hours. Idle stop after about 30 s (Chrome)
How to take it backClear site data, browser privacy settings
Inside an iframeNot listed

Data you get

What comes back: Registration and cache
Shape: object
How often: persists across visits

FieldTypeUnitRangePrecision
idle_stopintegersecondsabout 30approximate

Technical limits

  • Idle termination about 30 s, single event up to about 5 min (Chrome)
  • HTTPS only
  • Same origin scope
  • Safari 7 day cap on registrations without user visit
  • Cleared by Clear site data

The story

What it is

A background script a site installs, which stays on your device after you close the tab.

For you

You never see it. A site you visited can leave a small helper that makes it load faster and work offline. It can also stay around for a long time unless the browser clears it.

For makers

Makers use it for offline, caching, push and fast loads. It acts like a tiny server on your device. It can also keep an identity link or run tracking code, so browsers limit its lifetime.

Where you see it

TypeExampleApps
newsA news site caches pages so you can read offline on a plane.The Guardian
gamesA browser game caches its files, so it starts in a second the next time and works offline.None named
productivityA web editor like Google Docs keeps its code locally so it opens fast and works offline.Google Docs
shoppingA store caches its catalog so browsing feels instant on a weak signal.AliExpress
adsAn ad or tracking script installs a helper to survive cookie clearing and measure visits later.None named
messagingA web chat uses a helper to receive push messages when the tab is closed.None named
securityA malicious site installs a helper that keeps showing spam alerts after you leave.None named

Risks

  • Persists after leaving
  • Can hide tracking

What the platform says

Good uses and abuse

Legitimate uses

  • Offline apps, push, performance

Known abuse

  • Persistent hidden request interception, tracker caching

Scores

ScoreValueMeaning
Sensitivity3 of 5How revealing the data is
Utility5 of 5How useful it is to honest apps
Friction0 of 5How much the user has to do
Fingerprint bitsNot ratedRough identifying entropy, when known

History

  • 2015-01, Chrome 40: Shipped
  • 2018-03, Safari 11.1: Shipped in Safari
  • 2020-03, Safari 13.1: ITP 7 day storage cap covers registrations

Sources

How well checked: Based on official documentation.

On this page