Interface ServiceWorkerGlobalScope

This ServiceWorker API interface represents the global execution context of a service worker.

MDN Reference

interface ServiceWorkerGlobalScope {
    AbortController: typeof AbortController;
    AbortSignal: typeof AbortSignal;
    Blob: typeof Blob;
    Body: typeof Body;
    ByteLengthQueuingStrategy: typeof ByteLengthQueuingStrategy;
    Cache: typeof Cache;
    CacheStorage: typeof CacheStorage;
    CloseEvent: typeof CloseEvent;
    CompressionStream: typeof CompressionStream;
    CountQueuingStrategy: typeof CountQueuingStrategy;
    Crypto: typeof Crypto;
    CryptoKey: typeof CryptoKey;
    CustomEvent: typeof CustomEvent;
    DOMException: typeof DOMException;
    DecompressionStream: typeof DecompressionStream;
    ErrorEvent: typeof ErrorEvent;
    Event: typeof Event;
    EventTarget: typeof EventTarget;
    ExtendableEvent: typeof ExtendableEvent;
    FetchEvent: typeof FetchEvent;
    File: typeof File;
    FixedLengthStream: typeof FixedLengthStream;
    FormData: typeof FormData;
    GPUAdapter: typeof gpuGPUAdapter;
    GPUBufferUsage: typeof gpuGPUBufferUsage;
    GPUColorWrite: typeof gpuGPUColorWrite;
    GPUDeviceLostInfo: typeof gpuGPUDeviceLostInfo;
    GPUInternalError: typeof gpuGPUInternalError;
    GPUMapMode: typeof gpuGPUMapMode;
    GPUOutOfMemoryError: typeof gpuGPUOutOfMemoryError;
    GPUShaderStage: typeof gpuGPUShaderStage;
    GPUTextureUsage: typeof gpuGPUTextureUsage;
    GPUValidationError: typeof gpuGPUValidationError;
    HTMLRewriter: typeof HTMLRewriter;
    Headers: typeof Headers;
    IdentityTransformStream: typeof IdentityTransformStream;
    MessageEvent: typeof MessageEvent;
    PromiseRejectionEvent: typeof PromiseRejectionEvent;
    ReadableStream: {
        prototype: ReadableStream<any>;
        new (underlyingSource, strategy?): ReadableStream<Uint8Array>;
        new <R>(underlyingSource?, strategy?): ReadableStream<R>;
    };
    ReadableStreamBYOBReader: typeof ReadableStreamBYOBReader;
    ReadableStreamDefaultReader: typeof ReadableStreamDefaultReader;
    Request: typeof Request;
    Response: typeof Response;
    ScheduledEvent: typeof ScheduledEvent;
    SubtleCrypto: typeof SubtleCrypto;
    TailEvent: typeof TailEvent;
    TextDecoder: typeof TextDecoder;
    TextDecoderStream: typeof TextDecoderStream;
    TextEncoder: typeof TextEncoder;
    TextEncoderStream: typeof TextEncoderStream;
    TraceEvent: typeof TailEvent;
    TransformStream: typeof TransformStream;
    URL: typeof URL;
    URLPattern: typeof URLPattern;
    URLSearchParams: typeof URLSearchParams;
    WebSocket: typeof WebSocket;
    WebSocketPair: (new () => {
        0: WebSocket;
        1: WebSocket;
    });
    WebSocketRequestResponsePair: typeof WebSocketRequestResponsePair;
    WorkerGlobalScope: typeof WorkerGlobalScope;
    WritableStream: typeof WritableStream;
    WritableStreamDefaultWriter: typeof WritableStreamDefaultWriter;
    caches: CacheStorage;
    crypto: Crypto;
    origin: string;
    performance: Performance;
    scheduler: Scheduler;
    self: ServiceWorkerGlobalScope;
    addEventListener<Type>(type, handler, options?): void;
    atob(data): string;
    btoa(data): string;
    clearInterval(timeoutId): void;
    clearTimeout(timeoutId): void;
    dispatchEvent(event): boolean;
    fetch(input, init?): Promise<Response>;
    queueMicrotask(task): void;
    removeEventListener<Type>(type, handler, options?): void;
    reportError(error): void;
    setInterval(callback, msDelay?): number;
    setInterval<Args>(callback, msDelay?, ...args): number;
    setTimeout(callback, msDelay?): number;
    setTimeout<Args>(callback, msDelay?, ...args): number;
    structuredClone<T>(value, options?): T;
}

Hierarchy (view full)

Properties

AbortController: typeof AbortController
AbortSignal: typeof AbortSignal
Blob: typeof Blob
Body: typeof Body
ByteLengthQueuingStrategy: typeof ByteLengthQueuingStrategy
Cache: typeof Cache
CacheStorage: typeof CacheStorage
CloseEvent: typeof CloseEvent
CompressionStream: typeof CompressionStream
CountQueuingStrategy: typeof CountQueuingStrategy
Crypto: typeof Crypto
CryptoKey: typeof CryptoKey
CustomEvent: typeof CustomEvent
DOMException: typeof DOMException
DecompressionStream: typeof DecompressionStream
ErrorEvent: typeof ErrorEvent
Event: typeof Event
EventTarget: typeof EventTarget
ExtendableEvent: typeof ExtendableEvent
FetchEvent: typeof FetchEvent
File: typeof File
FixedLengthStream: typeof FixedLengthStream
FormData: typeof FormData
GPUAdapter: typeof gpuGPUAdapter
GPUBufferUsage: typeof gpuGPUBufferUsage
GPUColorWrite: typeof gpuGPUColorWrite
GPUDeviceLostInfo: typeof gpuGPUDeviceLostInfo
GPUInternalError: typeof gpuGPUInternalError
GPUMapMode: typeof gpuGPUMapMode
GPUOutOfMemoryError: typeof gpuGPUOutOfMemoryError
GPUShaderStage: typeof gpuGPUShaderStage
GPUTextureUsage: typeof gpuGPUTextureUsage
GPUValidationError: typeof gpuGPUValidationError
HTMLRewriter: typeof HTMLRewriter
Headers: typeof Headers
IdentityTransformStream: typeof IdentityTransformStream
MessageEvent: typeof MessageEvent
PromiseRejectionEvent: typeof PromiseRejectionEvent
ReadableStream: {
    prototype: ReadableStream<any>;
    new (underlyingSource, strategy?): ReadableStream<Uint8Array>;
    new <R>(underlyingSource?, strategy?): ReadableStream<R>;
}

Type declaration

ReadableStreamBYOBReader: typeof ReadableStreamBYOBReader
ReadableStreamDefaultReader: typeof ReadableStreamDefaultReader
Request: typeof Request
Response: typeof Response
ScheduledEvent: typeof ScheduledEvent
SubtleCrypto: typeof SubtleCrypto
TailEvent: typeof TailEvent
TextDecoder: typeof TextDecoder
TextDecoderStream: typeof TextDecoderStream
TextEncoder: typeof TextEncoder
TextEncoderStream: typeof TextEncoderStream
TraceEvent: typeof TailEvent
TransformStream: typeof TransformStream
URL: typeof URL
URLPattern: typeof URLPattern
URLSearchParams: typeof URLSearchParams
WebSocket: typeof WebSocket
WebSocketPair: (new () => {
    0: WebSocket;
    1: WebSocket;
})

Type declaration

WebSocketRequestResponsePair: typeof WebSocketRequestResponsePair
WorkerGlobalScope: typeof WorkerGlobalScope
WritableStream: typeof WritableStream
WritableStreamDefaultWriter: typeof WritableStreamDefaultWriter
caches: CacheStorage
crypto: Crypto
origin: string
performance: Performance
scheduler: Scheduler

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

    Returns void

  • Parameters

    • data: string

    Returns string

  • Parameters

    • data: string

    Returns string

  • Parameters

    • timeoutId: number

    Returns void

  • Parameters

    • timeoutId: number

    Returns void

  • Parameters

    • task: Function

    Returns void

  • Parameters

    • error: any

    Returns void

  • Parameters

    • callback: ((...args) => void)
        • (...args): void
        • Parameters

          • Rest ...args: any[]

          Returns void

    • Optional msDelay: number

    Returns number

  • Type Parameters

    • Args extends any[]

    Parameters

    • callback: ((...args) => void)
        • (...args): void
        • Parameters

          Returns void

    • Optional msDelay: number
    • Rest ...args: Args

    Returns number

  • Parameters

    • callback: ((...args) => void)
        • (...args): void
        • Parameters

          • Rest ...args: any[]

          Returns void

    • Optional msDelay: number

    Returns number

  • Type Parameters

    • Args extends any[]

    Parameters

    • callback: ((...args) => void)
        • (...args): void
        • Parameters

          Returns void

    • Optional msDelay: number
    • Rest ...args: Args

    Returns number