Constructor

QueuePlugin

new QueuePlugin()

Extends
module:workbox-background-sync.Queue

Example

<caption>When you want the workbox-sw framework to take care of
failed requests.</caption>
let bgQueue = new workbox.backgroundSync.QueuePlugin({
  callbacks: {
    replayDidSucceed: async(hash, res) => {
      self.registration.showNotification('Background sync demo', {
        body: 'Product has been purchased.',
        icon: '/images/shop-icon-384.png',
       });
    },
    replayDidFail: (hash) => {},
    requestWillEnqueue: (reqData) => {},
    requestWillDequeue: (reqData) => {},
  },
});

const requestWrapper = new workbox.runtimeCaching.RequestWrapper({
  plugins: [bgQueue],
});

const route = new workbox.routing.RegExpRoute({
  regExp: new RegExp('^https://jsonplaceholder.typicode.com'),
  handler: new workbox.runtimeCaching.NetworkOnly({requestWrapper}),
});

const router = new workbox.routing.Router();
router.registerRoute({route});

Methods

fetchDidFail

fetchDidFail(input) returns Promise

Wraps pushIntoQueue in a callback used by higher level framework. This function pushes a given request into the IndexedDb Queue. NOTE: If you are writting the fetch handler for background sync manually, please ignore this.

Parameter

input

Object

Returns

Promise Promise which resolves when the request is pushed in the queue.

getResponse

getResponse(id) returns Object

Sets the dbName, which is used to store the queue and requests defaults to bgQueueSyncDB.

Parameter

id

The ID of the request.

Inherited from
module:workbox-background-sync.Queue#getResponse
Returns

Fetched response of the request.

pushIntoQueue

pushIntoQueue(input) returns Promise

This function pushes a given request into the IndexedDb Queue.

Parameter

input

Inherited from
module:workbox-background-sync.Queue#pushIntoQueue
Returns

Promise which resolves when the request is pushed in the queue.

replayRequests

replayRequests() returns Promise

Replays all the requests in the queue, this can be used for custom timing of replaying requests may be in an environment where sync event is not supported.

Inherited from
module:workbox-background-sync.Queue#replayRequests
Returns

A listener for when the requests have been replayed.