Chartbreaker
    Preparing search index...

    Interface ServiceWorkerRegistration

    The ServiceWorkerRegistration interface of the Service Worker API represents the service worker registration. You register a service worker to control one or more pages that share the same origin. Available only in secure contexts.

    MDN Reference

    interface ServiceWorkerRegistration {
        active: ServiceWorker | null;
        cookies: CookieStoreManager;
        installing: ServiceWorker | null;
        navigationPreload: NavigationPreloadManager;
        onupdatefound: ((this: ServiceWorkerRegistration, ev: Event) => any) | null;
        pushManager: PushManager;
        scope: string;
        updateViaCache: ServiceWorkerUpdateViaCache;
        waiting: ServiceWorker | null;
        addEventListener<K extends "updatefound">(
            type: K,
            listener: (
                this: ServiceWorkerRegistration,
                ev: ServiceWorkerRegistrationEventMap[K],
            ) => any,
            options?: boolean | AddEventListenerOptions,
        ): void;
        addEventListener(
            type: string,
            listener: EventListenerOrEventListenerObject,
            options?: boolean | AddEventListenerOptions,
        ): void;
        dispatchEvent(event: Event): boolean;
        getNotifications(filter?: GetNotificationOptions): Promise<Notification[]>;
        removeEventListener<K extends "updatefound">(
            type: K,
            listener: (
                this: ServiceWorkerRegistration,
                ev: ServiceWorkerRegistrationEventMap[K],
            ) => any,
            options?: boolean | EventListenerOptions,
        ): void;
        removeEventListener(
            type: string,
            listener: EventListenerOrEventListenerObject,
            options?: boolean | EventListenerOptions,
        ): void;
        showNotification(
            title: string,
            options?: NotificationOptions,
        ): Promise<void>;
        unregister(): Promise<boolean>;
        update(): Promise<ServiceWorkerRegistration>;
    }

    Hierarchy (View Summary)

    Index

    Properties

    active: ServiceWorker | null

    The active read-only property of the ServiceWorkerRegistration interface returns a service worker whose ServiceWorker.state is activating or activated. This property is initially set to null.

    MDN Reference

    The cookies read-only property of the ServiceWorkerRegistration interface returns a reference to the CookieStoreManager interface, which enables a web app to subscribe to and unsubscribe from cookie change events in a service worker. This is an entry point for the Cookie Store API.

    MDN Reference

    installing: ServiceWorker | null

    The installing read-only property of the ServiceWorkerRegistration interface returns a service worker whose ServiceWorker.state is installing. This property is initially set to null.

    MDN Reference

    navigationPreload: NavigationPreloadManager

    The navigationPreload read-only property of the ServiceWorkerRegistration interface returns the NavigationPreloadManager associated with the current service worker registration.

    MDN Reference

    onupdatefound: ((this: ServiceWorkerRegistration, ev: Event) => any) | null
    pushManager: PushManager
    scope: string

    The scope read-only property of the ServiceWorkerRegistration interface returns a string representing a URL that defines a service worker's registration scope; that is, the range of URLs a service worker can control. This is set using the scope parameter specified in the call to ServiceWorkerContainer.register() which registered the service worker.

    MDN Reference

    The updateViaCache read-only property of the ServiceWorkerRegistration interface returns the value of the setting used to determine the circumstances in which the browser will consult the HTTP cache when it tries to update the service worker or any scripts that are imported via importScripts().

    MDN Reference

    waiting: ServiceWorker | null

    The waiting read-only property of the ServiceWorkerRegistration interface returns a service worker whose ServiceWorker.state is installed. This property is initially set to null.

    MDN Reference

    Methods

    • The dispatchEvent() method of the EventTarget sends an Event to the object, (synchronously) invoking the affected event listeners in the appropriate order. The normal event processing rules (including the capturing and optional bubbling phase) also apply to events dispatched manually with dispatchEvent().

      MDN Reference

      Parameters

      Returns boolean

    • The getNotifications() method of the ServiceWorkerRegistration interface returns a list of the notifications in the order that they were created from the current origin via the current service worker registration. Origins can have many active but differently-scoped service worker registrations. Notifications created by one service worker on the same origin will not be available to other active service workers on that same origin.

      MDN Reference

      Parameters

      Returns Promise<Notification[]>

    • The removeEventListener() method of the EventTarget interface removes an event listener previously registered with EventTarget.addEventListener() from the target. The event listener to be removed is identified using a combination of the event type, the event listener function itself, and various optional options that may affect the matching process; see Matching event listeners for removal.

      MDN Reference

      Type Parameters

      • K extends "updatefound"

      Parameters

      Returns void

    • The removeEventListener() method of the EventTarget interface removes an event listener previously registered with EventTarget.addEventListener() from the target. The event listener to be removed is identified using a combination of the event type, the event listener function itself, and various optional options that may affect the matching process; see Matching event listeners for removal.

      MDN Reference

      Parameters

      Returns void

    • The showNotification() method of the ServiceWorkerRegistration interface creates a notification on an active service worker.

      MDN Reference

      Parameters

      Returns Promise<void>

    • The unregister() method of the ServiceWorkerRegistration interface unregisters the service worker registration and returns a Promise. The promise will resolve to false if no registration was found, otherwise it resolves to true irrespective of whether unregistration happened or not (it may not unregister if someone else just called ServiceWorkerContainer.register() with the same scope.) The service worker will finish any ongoing operations before it is unregistered.

      MDN Reference

      Returns Promise<boolean>

    • The update() method of the ServiceWorkerRegistration interface attempts to update the service worker. It fetches the worker's script URL, and if the new worker is not byte-by-byte identical to the current worker, it installs the new worker. The fetch of the worker bypasses any browser caches if the previous fetch occurred over 24 hours ago.

      MDN Reference

      Returns Promise<ServiceWorkerRegistration>