Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

register-service-worker

Package Overview
Dependencies
Maintainers
2
Versions
16
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

register-service-worker

Script for registering service worker, with hooks

  • 1.6.1
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
105K
decreased by-41.4%
Maintainers
2
Weekly downloads
 
Created

What is register-service-worker?

The register-service-worker npm package is a utility for registering service workers in web applications. It simplifies the process of setting up service workers, handling updates, and managing the service worker lifecycle events.

What are register-service-worker's main functionalities?

Basic Service Worker Registration

This feature allows you to register a service worker with various lifecycle hooks such as ready, registered, cached, updatefound, updated, offline, and error. These hooks provide callbacks for different stages of the service worker's lifecycle.

import { register } from 'register-service-worker';

register('/service-worker.js', {
  ready() {
    console.log('Service worker is active.');
  },
  registered() {
    console.log('Service worker has been registered.');
  },
  cached() {
    console.log('Content has been cached for offline use.');
  },
  updatefound() {
    console.log('New content is downloading.');
  },
  updated() {
    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);
  }
});

Custom Service Worker Path

This feature allows you to specify a custom path for your service worker file. It provides the same lifecycle hooks as the basic registration but uses a different service worker script.

import { register } from 'register-service-worker';

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

Other packages similar to register-service-worker

Keywords

FAQs

Package last updated on 11 Feb 2019

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc