BackgroundService

Experimental

Defines events for background web platform features.

Commands

BackgroundService.startObserving

Enables event updates for the service.

Parameters
Name Type Description
service ServiceName

BackgroundService.stopObserving

Disables event updates for the service.

Parameters
Name Type Description
service ServiceName

BackgroundService.setRecording

Set the recording state for the service.

Parameters
Name Type Description
shouldRecord boolean
service ServiceName

BackgroundService.clearEvents

Clears all stored data for the service.

Parameters
Name Type Description
service ServiceName

Events

BackgroundService.recordingStateChanged

Called when the recording state for the service has been updated.

Parameters
Name Type Description
isRecording boolean
service ServiceName

BackgroundService.backgroundServiceEventReceived

Called with all existing backgroundServiceEvents when enabled, and all new
events afterwards if enabled and recording.

Parameters
Name Type Description
backgroundServiceEvent BackgroundServiceEvent

Types

ServiceName

(string)

The Background Service that will be associated with the commands/events.
Every Background Service operates independently, but they share the same
API.

Allowed Values
  • backgroundFetch
  • backgroundSync
  • pushMessaging
  • notifications
  • paymentHandler
  • periodicBackgroundSync

EventMetadata

(object)

A key-value pair for additional event information to pass along.

Properties
Name Type Description
key string
value string

BackgroundServiceEvent

(object)
Properties
Name Type Description
timestamp Network.TimeSinceEpoch Timestamp of the event (in seconds).
origin string The origin this event belongs to.
serviceWorkerRegistrationId ServiceWorker.RegistrationID The Service Worker ID that initiated the event.
service ServiceName The Background Service this event belongs to.
eventName string A description of the event.
instanceId string An identifier that groups related events together.
eventMetadata array<EventMetadata> A list of event-specific information.
storageKey string Storage key this event belongs to.

Summary