Secure context: This feature is available only in secure contexts (HTTPS), in some or all supporting browsers.
Note: This feature is available in Web Workers.
The Background Synchronization API enables a web app to defer tasks so that they can be run in a service worker once the user has a stable network connection.
The Background Synchronization API allows web applications to defer server synchronization work to their service worker to handle at a later time, if the device is offline. Uses may include sending requests in the background if they couldn't be sent while the application was being used.
For example, an email client application could let its users compose and send messages at any time, even when the device has no network connection. The application frontend just registers a sync request and the service worker gets alerted when the network is present again and handles the sync.
The SyncManager interface is available through ServiceWorkerRegistration.sync. A unique tag identifier is set to 'name' the sync event, which can then be listened for within the ServiceWorker script. Once the event is received you can then run any functionality available, such as sending requests to the server.
As this API relies on service workers, functionality provided by this API is only available in a secure context.
SyncManager Experimental
Registers tasks to be run in a service worker at a later time with network connectivity. These tasks are referred to as background sync requests.
SyncEvent Experimental
Represents a synchronization event, sent to the global scope of a ServiceWorker. It provides a way to run tasks in the service worker once the device has network connectivity.
The following additions to the Service Worker API provide an entry point for setting up background synchronization.
ServiceWorkerRegistration.sync Read only
Returns a reference to the SyncManager interface for registering tasks to run once the device has network connectivity.
sync eventAn event handler fired whenever a sync event occurs. This happens as soon as the network becomes available.
The following examples show how to use the interface.
The following asynchronous function registers a background sync from a browsing context:
async function syncMessagesLater() {
const registration = await navigator.serviceWorker.ready;
try {
await registration.sync.register("sync-messages");
} catch {
console.log("Background Sync could not be registered!");
}
}
This code checks to see if a background sync task with a given tag is registered.
navigator.serviceWorker.ready.then((registration) => {
registration.sync.getTags().then((tags) => {
if (tags.includes("sync-messages")) {
console.log("Messages sync already requested");
}
});
});
The following example shows how to respond to a background sync event in the service worker.
self.addEventListener("sync", (event) => {
if (event.tag === "sync-messages") {
event.waitUntil(sendOutboxMessages());
}
});
| Specification |
|---|
| Web Background Synchronization> |
| Desktop | Mobile | |||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|
| Chrome | Edge | Firefox | Opera | Safari | Chrome Android | Firefox for Android | Opera Android | Safari on IOS | Samsung Internet | WebView Android | WebView on iOS | |
Background_Synchronization_API |
49 | 79 | No | 36 | No | 49 | No | 36 | No | 5.0 | No | No |
getTags |
49 | 79 | No | 36 | No | 49 | No | 36 | No | 5.0 | No | No |
register |
49 | 79 | No | 36 | No | 49 | No | 36 | No | 5.0 | No | No |
worker_support |
6149–61Only available in theWindow and ServiceWorker global scopes. |
79 | No | No | No | 6149–61Only available in theWindow and ServiceWorker global scopes. |
No | No | No | 8.05.0–8.0Only available in theWindow and ServiceWorker global scopes. |
No | No |
| Desktop | Mobile | |||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|
| Chrome | Edge | Firefox | Opera | Safari | Chrome Android | Firefox for Android | Opera Android | Safari on IOS | Samsung Internet | WebView Android | WebView on iOS | |
Background_Synchronization_API |
49 | 79 | No | 24 | No | 49 | No | 24 | No | 5.0 | No | No |
© 2005–2025 MDN contributors.
Licensed under the Creative Commons Attribution-ShareAlike License v2.5 or later.
https://developer.mozilla.org/en-US/docs/Web/API/Background_Synchronization_API