Skip to content

isServiceWorker ​

The isServiceWorker function checks if the code is running in a Service Worker.

Syntax ​

typescript
isServiceWorker(): boolean;

Parameters ​

This function does not take any parameters.

Returns ​

TypeDescription
booleantrue if running in a Service Worker, false otherwise

Examples ​

typescript
isServiceWorker();
// => true (in Service Worker)
// => false (in other environments)

Notes ​

  • Checks for the existence of the global ServiceWorkerGlobalScope object and whether self is an instance of that scope.
  • Useful for conditioning Service Worker-specific executions.

References ​

Released under the MIT License.