Module Js_of_ocaml.ServiceWorker

Service Workers.

This module covers both sides of the API: the page-facing registration API (container, serviceWorkerContainer, serviceWorkerRegistration, serviceWorker) and the worker-side global scope (global, serviceWorkerGlobalScope and its events). The Cache API used inside a worker lives in Cache.

Service Workers require a secure context. The Promise-typed members use Promise.

class type serviceWorker = object ... end

A service worker, as seen from a controlled page. Inherits EventTarget.

class type registrationOptions = object ... end

Options for serviceWorkerContainer##register_withOptions. Create an empty record with empty_registration_options.

val empty_registration_options : unit -> registrationOptions Js.t
class type navigationPreloadState = object ... end

The state of a registration's navigation preload, as resolved by navigationPreloadManager##getState.

class type navigationPreloadManager = object ... end

Manages navigation preloading for a serviceWorkerRegistration, exposed as its navigationPreload.

class type serviceWorkerRegistration = object ... end

A registration of a service worker against a scope. Inherits EventTarget.

class type serviceWorkerContainer = object ... end

The page-facing entry point, exposed as navigator.serviceWorker (see container). Inherits EventTarget.

val container : unit -> serviceWorkerContainer Js.t Js.optdef

navigator.serviceWorker, or undefined when service workers are not supported (including non-secure contexts).

val is_supported : unit -> bool

Whether navigator.serviceWorker is available in the current environment.

Service worker global scope

The following bindings are meant to be used from inside a service worker (see global); they are not available on a controlled page.

class type extendableEvent = object ... end

Base class of events that may extend the service worker's lifetime via waitUntil.

class type fetchEvent = object ... end

The event passed to the worker's fetch handler.

class type 'a extendableMessageEvent = object ... end

The event delivered to the worker's message / messageerror handlers. Unlike a plain Dom_html.messageEvent it extends extendableEvent, so the handler can call waitUntil to keep the worker alive until asynchronous processing of the message finishes. The type parameter 'a is the type of the data payload.

class type client = object ... end

A client (a Window, worker or shared worker) controlled by the worker.

class type windowClient = object ... end

A client that is a top-level browsing context (a window/tab).

class type clientsQueryOptions = object ... end

Options for clients##matchAll_withOptions. Create an empty record with empty_clients_query_options.

val empty_clients_query_options : unit -> clientsQueryOptions Js.t
class type clients = object ... end

The worker's clients object, used to enumerate and message controlled clients.

class type serviceWorkerGlobalScope = object ... end

The global scope of a running service worker (its self). Inherits EventTarget.

val global : unit -> serviceWorkerGlobalScope Js.t

The service worker's global scope. Only meaningful when the current code is actually running as a service worker.