angular / 14.0.0 / api / service-worker / swupdate.html /

SwUpdate

class final

Subscribe to update notifications from the Service Worker, trigger update checks, and forcibly activate updates.

class SwUpdate {
  versionUpdates: Observable<VersionEvent>
  available: Observable<UpdateAvailableEvent>
  activated: Observable<UpdateActivatedEvent>
  unrecoverable: Observable<UnrecoverableStateEvent>
  isEnabled: boolean
  checkForUpdate(): Promise<boolean>
  activateUpdate(): Promise<boolean>
}

See also

Provided in

Properties

Property Description
versionUpdates: Observable<VersionEvent> Read-Only

Emits a VersionDetectedEvent event whenever a new version is detected on the server.

Emits a VersionInstallationFailedEvent event whenever checking for or downloading a new version fails.

Emits a VersionReadyEvent event whenever a new version has been downloaded and is ready for activation.

available: Observable<UpdateAvailableEvent> Read-Only

Emits an UpdateAvailableEvent event whenever a new app version is available.

Deprecated Use versionUpdates instead.

The of behavior available can be rebuild by filtering for the VersionReadyEvent:

import {filter, map} from 'rxjs/operators';
// ...
const updatesAvailable = swUpdate.versionUpdates.pipe(
  filter((evt): evt is VersionReadyEvent => evt.type === 'VERSION_READY'),
  map(evt => ({
    type: 'UPDATE_AVAILABLE',
    current: evt.currentVersion,
    available: evt.latestVersion,
  })));
activated: Observable<UpdateActivatedEvent> Read-Only

Emits an UpdateActivatedEvent event whenever the app has been updated to a new version.

Deprecated Use the return value of SwUpdate instead.

unrecoverable: Observable<UnrecoverableStateEvent> Read-Only

Emits an UnrecoverableStateEvent event whenever the version of the app used by the service worker to serve this client is in a broken state that cannot be recovered from without a full page reload.

isEnabled: boolean Read-Only

True if the Service Worker is enabled (supported by the browser and enabled via ServiceWorkerModule).

Methods

Checks for an update and waits until the new version is downloaded from the server and ready for activation.

checkForUpdate(): Promise<boolean>

Parameters

There are no parameters.

Returns

Promise<boolean>: a promise that

  • resolves to true if a new version was found and is ready to be activated.
  • resolves to false if no new version was found
  • rejects if any error occurs

Updates the current client (i.e. browser tab) to the latest version that is ready for activation.

activateUpdate(): Promise<boolean>

Parameters

There are no parameters.

Returns

Promise<boolean>: a promise that

  • resolves to true if an update was activated successfully
  • resolves to false if no update was available (for example, the client was already on the latest version).
  • rejects if any error occurs

© 2010–2022 Google, Inc.
Licensed under the Creative Commons Attribution License 4.0.
https://angular.io/api/service-worker/SwUpdate