Back to Content

Navigator: serviceWorker property

files/en-us/web/api/navigator/serviceworker/index.md

latest1.0 KB
Original Source

{{securecontext_header}}{{APIRef("Service Workers API")}}

The serviceWorker read-only property of the {{domxref("Navigator")}} interface returns the {{domxref("ServiceWorkerContainer")}} object for the associated document, which provides access to registration, removal, upgrade, and communication with the {{domxref("ServiceWorker")}}.

The feature may not be available in private mode.

Note that a worker can similarly access the {{domxref("ServiceWorkerContainer")}} for a document using {{domxref("WorkerNavigator.serviceWorker")}}.

Value

{{domxref("ServiceWorkerContainer")}}.

Examples

This code checks if the browser supports service workers.

js
if ("serviceWorker" in navigator) {
  // Supported!
}

Specifications

{{Specifications}}

Browser compatibility

{{Compat}}

See also