Movatterモバイル変換


[0]ホーム

URL:


  1. Web
  2. Web APIs
  3. ServiceWorkerGlobalScope
  4. sync

ServiceWorkerGlobalScope: sync event

Limited availability

This feature is not Baseline because it does not work in some of the most widely-used browsers.

Secure context: This feature is available only insecure contexts (HTTPS), in some or allsupporting browsers.

Note: This feature is only available inService Workers.

Thesync event of theServiceWorkerGlobalScope interface is fired when the page (or worker) that registered the event with theSyncManager is running and as soon as network connectivity is available.

This event is not cancelable and does not bubble.

Syntax

Use the event name in methods likeaddEventListener(), or set an event handler property.

js
addEventListener("sync", (event) => { })onsync = (event) => { }

Event type

ASyncEvent. Inherits fromExtendableEvent andEvent.

Event ExtendableEvent SyncEvent

Event properties

Inherits properties from its ancestor,ExtendableEvent andEvent.

SyncEvent.tagRead only

Returns the developer-defined identifier for thisSyncEvent.

SyncEvent.lastChanceRead only

Returnstrue if the user agent will not make further synchronization attempts after the current attempt.

Examples

The following example shows how to respond to a sync event in the service worker.

js
self.addEventListener("sync", (event) => {  if (event.tag === "sync-messages") {    event.waitUntil(sendOutboxMessages());  }});

You can also set up the event handler using theonsync property:

js
self.onsync = (event) => {  // …};

Specifications

Specification
Web Background Synchronization
# dom-serviceworkerglobalscope-onsync

Browser compatibility

See also

Help improve MDN

Learn how to contribute

This page was last modified on byMDN contributors.


[8]ページ先頭

©2009-2025 Movatter.jp