Chartbreaker
    Preparing search index...

    Interface ServiceWorker

    The ServiceWorker interface of the Service Worker API provides a reference to a service worker. Multiple browsing contexts (e.g., pages, workers, etc.) can be associated with the same service worker, each through a unique ServiceWorker object. Available only in secure contexts.

    MDN Reference

    interface ServiceWorker {
        onerror: ((this: AbstractWorker, ev: ErrorEvent) => any) | null;
        onstatechange: ((this: ServiceWorker, ev: Event) => any) | null;
        scriptURL: string;
        state: ServiceWorkerState;
        addEventListener<K extends keyof ServiceWorkerEventMap>(
            type: K,
            listener: (this: ServiceWorker, ev: ServiceWorkerEventMap[K]) => any,
            options?: boolean | AddEventListenerOptions,
        ): void;
        addEventListener(
            type: string,
            listener: EventListenerOrEventListenerObject,
            options?: boolean | AddEventListenerOptions,
        ): void;
        dispatchEvent(event: Event): boolean;
        postMessage(message: any, transfer: Transferable[]): void;
        postMessage(message: any, options?: StructuredSerializeOptions): void;
        removeEventListener<K extends keyof ServiceWorkerEventMap>(
            type: K,
            listener: (this: ServiceWorker, ev: ServiceWorkerEventMap[K]) => any,
            options?: boolean | EventListenerOptions,
        ): void;
        removeEventListener(
            type: string,
            listener: EventListenerOrEventListenerObject,
            options?: boolean | EventListenerOptions,
        ): void;
    }

    Hierarchy (View Summary)

    Index

    Properties

    onerror: ((this: AbstractWorker, ev: ErrorEvent) => any) | null
    onstatechange: ((this: ServiceWorker, ev: Event) => any) | null
    scriptURL: string

    Returns the ServiceWorker serialized script URL defined as part of ServiceWorkerRegistration. Must be on the same origin as the document that registers the ServiceWorker.

    MDN Reference

    The state read-only property of the ServiceWorker interface returns a string representing the current state of the service worker. It can be one of the following values: parsed, installing, installed, activating, activated, or redundant.

    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 postMessage() method of the ServiceWorker interface sends a message to the worker. The first parameter is the data to send to the worker. The data may be any JavaScript object which can be handled by the structured clone algorithm.

      MDN Reference

      Parameters

      Returns void

    • Parameters

      Returns void