# Service worker

“A service worker is an event-driven worker registered against an origin and a path. Service workers essentially act as proxy servers that sit between web applications, the browser, and the network (when available). They are intended, among other things, to enable the creation of effective offline experiences, intercept network requests and take appropriate action based on whether the network is available, and update assets residing on the server. They will also allow access to push notifications and background sync APIs.” - [MDN Web Docs](https://developer.mozilla.org/en-US/docs/Web/API/Service_Worker_API)

Our service worker implementation is based only on [Push API](https://developer.mozilla.org/en-US/docs/Web/API/Push_API).

If the user agrees to receive notifications through subscription form, then:

* service worker is registered in the user's browser,
* random Subscriber's Token with its VAPID key pair for data encryption is generated by provider and sent through HTTP request to the PushPushGo server,
* subscriber is saved in the PushPushGo database by giving them an internal Subscriber ID which is returned in response and saved in IndexedDB for further identification,
* based on HTTP headers, the subscriber is labeled in the PushPushGo database (operating system, language, browser, provider type, location guessed using GeoIPLookup).

In other words, the service worker is responsible for subscriber’s identification and notification delivery.


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://docs.pushpushgo.company/web-push/service-worker.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
