Constructor

Queue

new Queue(input)

Creates an instance of Queue with the given options

Parameter

input

Optional

Object

Example

When you want to push the requests manually
let bgQueue = new workbox.backgroundSync.Queue();
self.addEventListener('fetch', function(e) {
  if (!e.request.url.startsWith('https://jsonplaceholder.typicode.com')) {
    return;
  }

  const clone = e.request.clone();
  e.respondWith(fetch(e.request).catch((err) => {
    bgQueue.pushIntoQueue({
      request: clone,
    });
    throw err;
  }));
});

Methods

getResponse

getResponse(id) returns Object

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

Parameter

id

String

The ID of the request.

Returns

Object Fetched response of the request.

pushIntoQueue

pushIntoQueue(input) returns Promise

This function pushes a given request into the IndexedDb Queue.

Parameter

input

Object

Returns

Promise 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.

Returns

Promise A listener for when the requests have been replayed.