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

Documentation ServiceWorkerGlobalScope by Mozilla Contributors, licensed under CC-BY-SA 2.5.

See also:

Variables

read onlyclients:Clients

Contains the Clients object associated with the service worker.

onactivate:Function

An event handler fired whenever an activate event occurs — when a ServiceWorkerRegistration acquires a new ServiceWorkerRegistration.active worker.

onfetch:Function

An event handler fired whenever a fetch event occurs — when a GlobalFetch.fetch is called.

oninstall:Function

An event handler fired whenever an install event occurs — when a ServiceWorkerRegistration acquires a new ServiceWorkerRegistration.installing worker.

onmessage:Function

An event handler fired whenever a message event occurs — when incoming messages are received. Controlled pages can use the MessagePort.postMessage() method to send messages to service workers. The service worker can optionally send a response back via the MessagePort exposed in event.data.port, corresponding to the controlled page.

onnotificationclick:Function

An event handler fired whenever a notificationclick event occurs — when a user clicks on a displayed notification.

onnotificationclose:Function

An event handler fired whenever a notificationclose event occurs — when a user closes a displayed notification.

onpush:Function

An event handler fired whenever a push event occurs — when a server push notification is received.

onpushsubscriptionchange:Function

An event handler fired whenever a pushsubscriptionchange event occurs — when a push subscription has been invalidated, or is about to be invalidated (e.g. when a push service sets an expiration time.)

read onlyregistration:ServiceWorkerRegistration

Contains the ServiceWorkerRegistration object that represents the service worker's registration.

Methods

skipWaiting():Promise<Void>

Allows the current service worker registration to progress from waiting to active state while service worker clients are using it.

Throws:

null

DOMError

Inherited Variables

Defined by WorkerGlobalScope

read onlycrypto:Crypto

read onlylocation:WorkerLocation

Returns the WorkerLocation associated with the worker. It is a specific location object, mostly a subset of the Location for browsing scopes, but adapted to workers.

onerror:(EitherType<Event, String>, String, Int, Int, Dynamic) ‑> Dynamic

Is an EventHandler representing the code to be called when the error event is raised.

onoffline:Function

Is an EventHandler representing the code to be called when the offline event is raised.

ononline:Function

Is an EventHandler representing the code to be called when the online event is raised.

read onlyorigin:String

read onlyperformance:Performance

Returns the Performance associated with the worker. It is a regular performance object, except that only a subset of its property and methods are available to workers.

read onlyself:WorkerGlobalScope

Returns a reference to the WorkerGlobalScope itself. Most of the time it is a specific scope like DedicatedWorkerGlobalScopeSharedWorkerGlobalScope or ServiceWorkerGlobalScope.

Inherited Methods

Defined by WorkerGlobalScope

atob(atob:String):String

Throws:

null

DOMError

btoa(btoa:String):String

Throws:

null

DOMError

@:value({ handle : 0 })clearInterval(handle:Int = 0):Void

@:value({ handle : 0 })clearTimeout(handle:Int = 0):Void

createImageBitmap(aImage:ImageElement, aOffset:Int, aLength:Int, aFormat:ImageBitmapFormat, aLayout:Array<ChannelPixelLayout>):Promise<ImageBitmap>

createImageBitmap(aImage:VideoElement):Promise<ImageBitmap>

createImageBitmap(aImage:CanvasElement):Promise<ImageBitmap>

createImageBitmap(aImage:Blob):Promise<ImageBitmap>

createImageBitmap(aImage:ImageData):Promise<ImageBitmap>

createImageBitmap(aImage:CanvasRenderingContext2D):Promise<ImageBitmap>

createImageBitmap(aImage:ImageBitmap):Promise<ImageBitmap>

createImageBitmap(aImage:ArrayBufferView):Promise<ImageBitmap>

createImageBitmap(aImage:ArrayBuffer):Promise<ImageBitmap>

createImageBitmap(aImage:VideoElement, aSx:Int, aSy:Int, aSw:Int, aSh:Int):Promise<ImageBitmap>

createImageBitmap(aImage:CanvasElement, aSx:Int, aSy:Int, aSw:Int, aSh:Int):Promise<ImageBitmap>

createImageBitmap(aImage:Blob, aSx:Int, aSy:Int, aSw:Int, aSh:Int):Promise<ImageBitmap>

createImageBitmap(aImage:ImageData, aSx:Int, aSy:Int, aSw:Int, aSh:Int):Promise<ImageBitmap>

createImageBitmap(aImage:CanvasRenderingContext2D, aSx:Int, aSy:Int, aSw:Int, aSh:Int):Promise<ImageBitmap>

createImageBitmap(aImage:ImageBitmap, aSx:Int, aSy:Int, aSw:Int, aSh:Int):Promise<ImageBitmap>

createImageBitmap(aImage:ArrayBufferView, aSx:Int, aSy:Int, aSw:Int, aSh:Int):Promise<ImageBitmap>

createImageBitmap(aImage:ArrayBuffer, aSx:Int, aSy:Int, aSw:Int, aSh:Int):Promise<ImageBitmap>

createImageBitmap(aImage:VideoElement, aOffset:Int, aLength:Int, aFormat:ImageBitmapFormat, aLayout:Array<ChannelPixelLayout>):Promise<ImageBitmap>

createImageBitmap(aImage:CanvasElement, aOffset:Int, aLength:Int, aFormat:ImageBitmapFormat, aLayout:Array<ChannelPixelLayout>):Promise<ImageBitmap>

createImageBitmap(aImage:Blob, aOffset:Int, aLength:Int, aFormat:ImageBitmapFormat, aLayout:Array<ChannelPixelLayout>):Promise<ImageBitmap>

createImageBitmap(aImage:ImageData, aOffset:Int, aLength:Int, aFormat:ImageBitmapFormat, aLayout:Array<ChannelPixelLayout>):Promise<ImageBitmap>

createImageBitmap(aImage:CanvasRenderingContext2D, aOffset:Int, aLength:Int, aFormat:ImageBitmapFormat, aLayout:Array<ChannelPixelLayout>):Promise<ImageBitmap>

createImageBitmap(aImage:ImageBitmap, aOffset:Int, aLength:Int, aFormat:ImageBitmapFormat, aLayout:Array<ChannelPixelLayout>):Promise<ImageBitmap>

createImageBitmap(aImage:ArrayBufferView, aOffset:Int, aLength:Int, aFormat:ImageBitmapFormat, aLayout:Array<ChannelPixelLayout>):Promise<ImageBitmap>

createImageBitmap(aImage:ArrayBuffer, aOffset:Int, aLength:Int, aFormat:ImageBitmapFormat, aLayout:Array<ChannelPixelLayout>):Promise<ImageBitmap>

createImageBitmap(aImage:ImageElement):Promise<ImageBitmap>

createImageBitmap(aImage:ImageElement, aSx:Int, aSy:Int, aSw:Int, aSh:Int):Promise<ImageBitmap>

Throws:

null

DOMError

dump(?str:String):Void

Allows you to write a message to stdout — i.e. in your terminal. This is the same as Firefox's window.dump, but for workers.

importScripts(urls:Rest<String>):Void

Imports one or more scripts into the worker's scope. You can specify as many as you'd like, separated by commas. For example: importScripts('foo.js', 'bar.js');

Throws:

null

DOMError

@:value({ timeout : 0 })setInterval(handler:String, timeout:Int = 0, unused:Rest<Dynamic>):Int

@:value({ timeout : 0 })setInterval(handler:Function, timeout:Int = 0, arguments:Rest<Dynamic>):Int

Throws:

null

DOMError

@:value({ timeout : 0 })setTimeout(handler:String, timeout:Int = 0, unused:Rest<Dynamic>):Int

@:value({ timeout : 0 })setTimeout(handler:Function, timeout:Int = 0, arguments:Rest<Dynamic>):Int

Throws:

null

DOMError

Defined by EventTarget

addEventListener(type:String, listener:Function, ?options:EitherType<AddEventListenerOptions, Bool>, ?wantsUntrusted:Bool):Void

addEventListener(type:String, listener:EventListener, ?options:EitherType<AddEventListenerOptions, Bool>, ?wantsUntrusted:Bool):Void

Register an event handler of a specific event type on the EventTarget.

Throws:

null

DOMError

dispatchEvent(event:Event):Bool

Dispatch an event to this EventTarget.

Throws:

null

DOMError

removeEventListener(type:String, listener:Function, ?options:EitherType<EventListenerOptions, Bool>):Void

removeEventListener(type:String, listener:EventListener, ?options:EitherType<EventListenerOptions, Bool>):Void

Removes an event listener from the EventTarget.

Throws:

null

DOMError