# @chaitanyapotti/register-service-worker

> Script for registering service worker, with hooks

Latest version **1.7.4** (published 2024-03-12) · MIT license · 0 weekly downloads

## Install

```sh
npm install @chaitanyapotti/register-service-worker
pnpm add @chaitanyapotti/register-service-worker
yarn add @chaitanyapotti/register-service-worker
bun add @chaitanyapotti/register-service-worker
```

## Health

**Score 20/100 (F)** — status: abandoned.

Positive: has types; no vulnerabilities.

Warnings: low downloads; no esm support.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 1.7.4 |
| Published | 2024-03-12 |
| First published | 2020-03-29 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | bundled |
| Module format | CommonJS |
| Dependencies | 0 |
| Unpacked size | 22.4 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 0 |
| Author | Chaitanya Potti |
| Maintainers | chaitanyapotti |
| Keywords | service-worker |

## Links

- npm: https://www.npmjs.com/package/@chaitanyapotti/register-service-worker
- Repository: https://github.com/chaitanyapotti/register-service-worker
- Homepage: https://github.com/chaitanyapotti/register-service-worker#readme
- Issues: https://github.com/chaitanyapotti/register-service-worker/issues
- npm.io page: https://npm.io/package/@chaitanyapotti/register-service-worker

## Alternatives

- [cron](https://npm.io/package/cron.md) — 4.9M weekly downloads
- [@vercel/queue](https://npm.io/package/@vercel/queue.md) — 731.6K weekly downloads
- [create-sonicjs](https://npm.io/package/create-sonicjs.md) — 1.6K weekly downloads
- [@exellix/jobs-api](https://npm.io/package/@exellix/jobs-api.md) — 941 weekly downloads
- [@forwardimpact/libskill](https://npm.io/package/@forwardimpact/libskill.md) — 575 weekly downloads

## Recent versions

- 1.7.4 (latest) — 2024-03-12
- 1.7.3 — 2020-04-13
- 1.7.2 — 2020-03-29

## README

# register-service-worker

A script to simplify service worker registration with hooks for common events.

## Usage

**Note:** this script uses ES modules export and is expected to be used with a client side bundler that can handle ES modules syntax.

``` js
import { register } from 'register-service-worker'

register('/service-worker.js', {
  registrationOptions: { scope: './' },
  ready (registration) {
    console.log('Service worker is active.')
  },
  registered (registration) {
    console.log('Service worker has been registered.')
  },
  cached (registration) {
    console.log('Content has been cached for offline use.')
  },
  updatefound (registration) {
    console.log('New content is downloading.')
  },
  updated (registration) {
    console.log('New content is available; please refresh.')
  },
  offline () {
    console.log('No internet connection found. App is running in offline mode.')
  },
  error (error) {
    console.error('Error during service worker registration:', error)
  }
})
```

The `ready`, `registered`, `cached`, `updatefound` and `updated` events passes a [ServiceWorkerRegistration](https://developer.mozilla.org/en-US/docs/Web/API/ServiceWorkerRegistration) instance in their arguments.

The `registrationOptions` object will be passed as the second argument to [`ServiceWorkerContainer.register()`](https://developer.mozilla.org/en-US/docs/Web/API/ServiceWorkerContainer/register#Parameters)

---
_Source: https://npm.io/package/@chaitanyapotti/register-service-worker · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
