AWS Amplify API
AWS Amplify Home
Options
All

- Public
- Public/Protected
- All

Inherited Externals Only exported
Menu

Provides a means to registering a service worker in the browser and communicating with it via postMessage events. https://developer.mozilla.org/en-US/docs/Web/API/Service_Worker_API/

postMessage events are currently not supported in all browsers. See: https://developer.mozilla.org/en-US/docs/Web/API/Service_Worker_API

At the minmum this class will register the service worker and listen and attempt to dispatch messages on state change and record analytics events based on the service worker lifecycle.

### Hierarchy

- ServiceWorkerClass

## Index

### Constructors

- constructor

### Accessors

- serviceWorker

### Methods

- _setupListeners
- enablePush
- register
- send

## Constructors

### constructor

- new ServiceWorkerClass(): ServiceWorkerClass

- - Defined in core/src/ServiceWorker/ServiceWorker.ts:44

  #### Returns ServiceWorkerClass

## Accessors

### serviceWorker

serviceWorker:

- Defined in core/src/ServiceWorker/ServiceWorker.ts:51

Get the currently active service worker

## Methods

### _setupListeners

- _setupListeners(): void

- - Defined in core/src/ServiceWorker/ServiceWorker.ts:177

  Listen for service worker state change and message events https://developer.mozilla.org/en-US/docs/Web/API/ServiceWorker/state

  #### Returns void

### enablePush

- enablePush(publicKey: string): any

- - Defined in core/src/ServiceWorker/ServiceWorker.ts:107

  Enable web push notifications. If not subscribed, a new subscription will be created and registered. Test Push Server: https://web-push-codelab.glitch.me/ Push Server Libraries: https://github.com/web-push-libs/ API Doc: https://developers.google.com/web/fundamentals/codelabs/push-notifications/

  #### Parameters

  - ##### publicKey: string

  #### Returns any

      - resolve(PushSubscription)

  - reject(Error)

### register

- register(filePath?: string, scope?: string): any

- - Defined in core/src/ServiceWorker/ServiceWorker.ts:67

  Register the service-worker.js file in the browser Make sure the service-worker.js is part of the build for example with Angular, modify the angular-cli.json file and add to "assets" array "service-worker.js"

  #### Parameters

  - ##### Default value filePath: string = "/service-worker.js"

  - ##### Default value scope: string = "/"

  #### Returns any

      - resolve(ServiceWorkerRegistration)
      - reject(Error)

### send

- send(message: any | string): void

- - Defined in core/src/ServiceWorker/ServiceWorker.ts:167

  Send a message to the service worker. The service worker needs to implement `self.addEventListener('message') to handle the message. This currently does not work in Safari or IE.

  #### Parameters

  - ##### message: any | string

  #### Returns void