Interface SharedWorkerGlobalScope

    interface SharedWorkerGlobalScope {
        caches: CacheStorage;
        crossOriginIsolated: boolean;
        crypto: Crypto;
        fonts: FontFaceSet;
        indexedDB: IDBFactory;
        isSecureContext: boolean;
        location: WorkerLocation;
        name: string;
        navigator: WorkerNavigator;
        onconnect: ((this: SharedWorkerGlobalScope, ev: MessageEvent<any>) => any);
        onerror: ((this: WorkerGlobalScope, ev: ErrorEvent) => any);
        onlanguagechange: ((this: WorkerGlobalScope, ev: Event) => any);
        onoffline: ((this: WorkerGlobalScope, ev: Event) => any);
        ononline: ((this: WorkerGlobalScope, ev: Event) => any);
        onrejectionhandled: ((this: WorkerGlobalScope, ev: PromiseRejectionEvent) => any);
        onunhandledrejection: ((this: WorkerGlobalScope, ev: PromiseRejectionEvent) => any);
        origin: string;
        performance: Performance;
        self: WorkerGlobalScope & typeof globalThis;
        addEventListener<K>(type: K, listener: ((this: SharedWorkerGlobalScope, ev: SharedWorkerGlobalScopeEventMap[K]) => any), options?: boolean | AddEventListenerOptions): void;
        addEventListener(type: string, listener: EventListenerOrEventListenerObject, options?: boolean | AddEventListenerOptions): void;
        atob(data: string): string;
        btoa(data: string): string;
        clearInterval(id: number): void;
        clearTimeout(id: number): void;
        close(): void;
        createImageBitmap(image: ImageBitmapSource, options?: ImageBitmapOptions): Promise<ImageBitmap>;
        createImageBitmap(image: ImageBitmapSource, sx: number, sy: number, sw: number, sh: number, options?: ImageBitmapOptions): Promise<ImageBitmap>;
        dispatchEvent(event: Event): boolean;
        fetch(input: RequestInfo | URL, init?: RequestInit): Promise<Response>;
        importScripts(...urls: (string | URL)[]): void;
        queueMicrotask(callback: VoidFunction): void;
        removeEventListener<K>(type: K, listener: ((this: SharedWorkerGlobalScope, ev: SharedWorkerGlobalScopeEventMap[K]) => any), options?: boolean | EventListenerOptions): void;
        removeEventListener(type: string, listener: EventListenerOrEventListenerObject, options?: boolean | EventListenerOptions): void;
        reportError(e: any): void;
        setInterval(handler: TimerHandler, timeout?: number, ...arguments: any[]): number;
        setTimeout(handler: TimerHandler, timeout?: number, ...arguments: any[]): number;
        structuredClone<T>(value: T, options?: StructuredSerializeOptions): T;
    }
    Hierarchy

    Properties

    caches: CacheStorage

    Available only in secure contexts.

    MDN Reference

    crossOriginIsolated: boolean
    crypto: Crypto
    indexedDB: IDBFactory
    isSecureContext: boolean
    location: WorkerLocation

    Returns workerGlobal's WorkerLocation object.

    MDN Reference

    name: string

    Returns sharedWorkerGlobal's name, i.e. the value given to the SharedWorker constructor. Multiple SharedWorker objects can correspond to the same shared worker (and SharedWorkerGlobalScope), by reusing the same name.

    MDN Reference

    navigator: WorkerNavigator

    Returns workerGlobal's WorkerNavigator object.

    MDN Reference

    onconnect: ((this: SharedWorkerGlobalScope, ev: MessageEvent<any>) => any)
    onerror: ((this: WorkerGlobalScope, ev: ErrorEvent) => any)
    onlanguagechange: ((this: WorkerGlobalScope, ev: Event) => any)
    onoffline: ((this: WorkerGlobalScope, ev: Event) => any)
    ononline: ((this: WorkerGlobalScope, ev: Event) => any)
    onrejectionhandled: ((this: WorkerGlobalScope, ev: PromiseRejectionEvent) => any)
    onunhandledrejection: ((this: WorkerGlobalScope, ev: PromiseRejectionEvent) => any)
    origin: string
    performance: Performance
    self: WorkerGlobalScope & typeof globalThis

    Returns workerGlobal.

    MDN Reference

    Methods

    • Appends an event listener for events whose type attribute value is type. The callback argument sets the callback that will be invoked when the event is dispatched.

      The options argument sets listener-specific options. For compatibility this can be a boolean, in which case the method behaves exactly as if the value was specified as options's capture.

      When set to true, options's capture prevents callback from being invoked when the event's eventPhase attribute value is BUBBLING_PHASE. When false (or not present), callback will not be invoked when event's eventPhase attribute value is CAPTURING_PHASE. Either way, callback will be invoked if event's eventPhase attribute value is AT_TARGET.

      When set to true, options's passive indicates that the callback will not cancel the event by invoking preventDefault(). This is used to enable performance optimizations described in § 2.8 Observing event listeners.

      When set to true, options's once indicates that the callback will only be invoked once after which the event listener will be removed.

      If an AbortSignal is passed for options's signal, then the event listener will be removed when signal is aborted.

      The event listener is appended to target's event listener list and is not appended if it has the same type, callback, and capture.

      MDN Reference

      Type Parameters

      Parameters

      Returns void

    • Appends an event listener for events whose type attribute value is type. The callback argument sets the callback that will be invoked when the event is dispatched.

      The options argument sets listener-specific options. For compatibility this can be a boolean, in which case the method behaves exactly as if the value was specified as options's capture.

      When set to true, options's capture prevents callback from being invoked when the event's eventPhase attribute value is BUBBLING_PHASE. When false (or not present), callback will not be invoked when event's eventPhase attribute value is CAPTURING_PHASE. Either way, callback will be invoked if event's eventPhase attribute value is AT_TARGET.

      When set to true, options's passive indicates that the callback will not cancel the event by invoking preventDefault(). This is used to enable performance optimizations described in § 2.8 Observing event listeners.

      When set to true, options's once indicates that the callback will only be invoked once after which the event listener will be removed.

      If an AbortSignal is passed for options's signal, then the event listener will be removed when signal is aborted.

      The event listener is appended to target's event listener list and is not appended if it has the same type, callback, and capture.

      MDN Reference

      Parameters

      Returns void

    • Aborts sharedWorkerGlobal.

      MDN Reference

      Returns void

    • Dispatches a synthetic event event to target and returns true if either event's cancelable attribute value is false or its preventDefault() method was not invoked, and false otherwise.

      MDN Reference

      Parameters

      Returns boolean

    • Fetches each URL in urls, executes them one-by-one in the order they are passed, and then returns (or throws if something went amiss).

      MDN Reference

      Parameters

      • Rest...urls: (string | URL)[]

      Returns void