Service worker lifetime
A background script registered by a site that persists after the tab is closed.
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
| Browser | Status | First version | Released | Note |
|---|---|---|---|---|
| Chrome | Supported | 40 | 2015-01-21 | None |
| Edge | Supported | 17 | 2018-04-30 | None |
| Firefox | Supported | 44 | 2016-01-26 | None |
| Safari | Supported | 11.1 | 2018-04-12 | None |
| Safari on iPhone | Supported | 11.3 | 2018-03-29 | None |
| Chrome on Android | Supported | 40 | 2015-01-21 | None |
| Samsung Internet | Supported | 4.0 | 2016-03-11 | None |
How a site asks for it
| API | navigator.serviceWorker.register(url) |
| Browser compat keys | api.ServiceWorkerContainer.register |
| How access is granted | none |
| What the user sees | None |
| Needs a secure context (HTTPS) | Yes |
| Needs a user gesture | No |
| How long it lasts | Registration 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 back | Clear site data, browser privacy settings |
| Inside an iframe | Not listed |
Data you get
What comes back: Registration and cache
Shape: object
How often: persists across visits
| Field | Type | Unit | Range | Precision |
|---|---|---|---|---|
idle_stop | integer | seconds | about 30 | approximate |
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
| Type | Example | Apps |
|---|---|---|
| news | A news site caches pages so you can read offline on a plane. | The Guardian |
| games | A browser game caches its files, so it starts in a second the next time and works offline. | None named |
| productivity | A web editor like Google Docs keeps its code locally so it opens fast and works offline. | Google Docs |
| shopping | A store caches its catalog so browsing feels instant on a weak signal. | AliExpress |
| ads | An ad or tracking script installs a helper to survive cookie clearing and measure visits later. | None named |
| messaging | A web chat uses a helper to receive push messages when the tab is closed. | None named |
| security | A 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
- WebKit: Tracking prevention. Safari limits how long background scripts and site data can live for sites you do not use.
Good uses and abuse
Legitimate uses
- Offline apps, push, performance
Known abuse
- Persistent hidden request interception, tracker caching
Scores
| Score | Value | Meaning |
|---|---|---|
| Sensitivity | 3 of 5 | How revealing the data is |
| Utility | 5 of 5 | How useful it is to honest apps |
| Friction | 0 of 5 | How much the user has to do |
| Fingerprint bits | Not rated | Rough 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
Related capabilities
Related
- Push, periodic sync and background fetch. Can wake a site's background script after you leave, through push, timed sync or downloads
- Cache Storage. Can keep copies of pages and files so the site opens without internet
Sources
How well checked: Based on official documentation.