Skip to content
AnswerWell geo Documentation

Research · 8 min read · Answerwell

Service Worker Background Sync, Push Messaging, and App Badging

How installed PWAs use Background Sync, Periodic Background Sync, Push, and the App Badging API—and how to debug them in DevTools.

This page summarizes how Chrome capabilities documentation and related guides describe service worker background work: retrying failed requests, prefetching content, receiving push messages, showing notifications, and updating app icon badges on installed progressive web apps. Most of the material below comes from Chrome; Cloudflare Agents illustrates server-timed delivery with the same web standards.

Background services: what runs when the tab is closed

Section titled “Background services: what runs when the tab is closed”

A background service is functionally similar to a background process: JavaScript APIs let a site send and receive updates even when the user does not have your site open. Chrome DevTools groups several of these under Application → Background services, including background fetch, background sync, notifications, speculative loads, and push messages.

The Background services section of Chrome DevTools is a collection of tools for the JavaScript APIs that enables your website to send and receive updates even when a user does not have your website open.

— Chrome, Debug background services

For installed PWAs, the same service worker often powers offline caching, sync retries, periodic downloads, push handling, and badge updates.

Background Sync API: retry failed requests when back online

Section titled “Background Sync API: retry failed requests when back online”

Background Sync (one-off sync) solves a common offline problem: if a POST, PUT, or DELETE fails because the user lost connectivity or the server was unreachable, the user might never retry manually.

When a service worker detects a failed network request, it can register to receive a sync event when the browser detects that connectivity has returned. The sync event can be delivered even if the user has navigated away from the page that registered it, making it more effective than other methods of retrying failed requests.

— Chrome, Retrying requests when back online

Workbox Background Sync wraps this API. The BackgroundSyncPlugin queues failed requests and replays them when sync events fire; browsers that support Background Sync use browser-managed backoff, while unsupported browsers retry when the service worker starts.

BackgroundSyncPlugin hooks into fetchDidFail, which runs only when fetch throws—typically a network failure. Responses with 4xx or 5xx status codes are not retried unless you add custom logic (for example a fetchDidSucceed handler that throws on server errors). See Retrying requests when back online and workbox-background-sync.

Each queue name must be unique to your origin; it becomes part of the sync tag and the IndexedDB object store. With maxRetentionTime set in minutes, Workbox stops retrying after that window (for example 24 hours).

Periodic Background Sync API: prefetch before the user opens the app

Section titled “Periodic Background Sync API: prefetch before the user opens the app”

Periodic background sync is not the same API as one-off background sync. One-off sync mainly re-sends data to a server after a failed request; periodic sync downloads data in the background so fresh content is ready at launch—closer to native app prefetch behavior.

Periodic Background Sync enables web applications to periodically synchronize data in the background, bringing web apps closer to the behavior of a platform-specific app.

— Chrome, Richer offline experiences with the Periodic Background Sync API

Rules Chrome applies before periodicsync fires

Section titled “Rules Chrome applies before periodicsync fires”

In Chrome, periodic background sync is restricted to reduce waste and align with user intent:

Requirement Meaning
Installed PWA The app must be installed and launched as a distinct application—not a normal tab.
Site engagement A positive site engagement score; frequency scales with use. Stops if the user stops engaging.
Known network Sync runs only on networks the device has used before; Chrome recommends trustworthy networks.
Browser-controlled timing Developers set minInterval, but actual cadence depends on engagement, power, and connectivity.

Query permission with navigator.permissions.query({ name: 'periodic-background-sync' }), register via registration.periodicSync.register(tag, { minInterval }), and handle periodicsync in the service worker. Full patterns appear in Periodic Background Sync.

Push API and notifications: server messages to the service worker

Section titled “Push API and notifications: server messages to the service worker”

The Push API lets a server send a message to an installed client’s service worker, which can run JavaScript with no foreground page. That path is the standard way to wake a worker for high-priority updates.

The Push API allows servers to send messages to service workers, which can run JavaScript code even when no foreground page is running. Thus, a server push could update the badge by calling navigator.setAppBadge().

— Chrome, Badging for app icons

In Chrome (and most browsers), a push often must surface as a user-visible notification when the message arrives, which makes silent badge-only push updates impractical unless showing a notification is acceptable. Users must grant notification permission to receive push.

On the server, any push provider can target the browser’s push service; for Chrome users, messages route through Firebase Cloud Messaging as the push service, as described in Use Web Push. Cloudflare’s push notifications guide shows storing subscriptions, scheduling delivery, and calling web-push from a durable backend—without replacing the browser’s push subscription flow.

Asking for notification permission on page load produces prompts that may not match user intent. Lighthouse flags requests for notification permission on page load as a best-practice issue; see Requests the notification permission on page load.

Chrome once explored Notification Triggers for time-based local notifications without network at fire time. Development has ended because consistent cross-platform behavior and pruning stale schedules were not achievable; periodic background sync cadence and push limitations were cited in feedback. Historical API details remain in Notification Triggers API for reference only.

App Badging API: unread counts on the installed app icon

Section titled “App Badging API: unread counts on the installed app icon”

The App Badging API exposes navigator.setAppBadge(number) and navigator.clearAppBadge() on installed web apps.

The App Badging API allows installed web apps to set an application-wide badge, shown in an operating-system-specific place associated with the application (such as the shelf or home screen).

— Chrome, Badging for app icons

Badges can signal unread chat or mail, completed background tasks, or game turns. They update frequently without interrupting the user and, unlike notifications, don’t need the user’s permission in the documented model.

Platform App Badging API
Windows, macOS Chrome 81+, Edge 81+
ChromeOS Was in development at time of writing
Android (installed PWA) API not supported; OS may show a dot when there is an unread notification

Do not assume exact numeric display: user agents may cap values (for example showing 99+). Call setAppBadge(unreadCount) with the real count and let the platform render it. Setting 0 is equivalent to clearAppBadge().

Chrome expects installability criteria for full badging behavior, but the docs recommend feature-detecting and calling the API when it exists rather than branching on install state, because other browsers may surface badges differently. Try the App Badging API demo from an installed PWA.

Combining push and periodic sync for badges

Section titled “Combining push and periodic sync for badges”

While not perfect, using Push API and periodic background sync together provides a good solution. High priority information is delivered via the Push API, showing a notification and updating the badge. And lower priority information is delivered by updating the badge, either when the page is open, or via periodic background sync.

— Chrome, Badging for app icons

Chrome extensions: Web Push vs browser.gcm

Section titled “Chrome extensions: Web Push vs browser.gcm”

Extensions can use the same Push API flow as the open web: push wakes the extension service worker even if suspended. Chrome recommends preferring web standards over extension-specific APIs.

In general, it is always best practice to use the web standard, rather than an extension specific API. Unless you have a specific need to use browser.gcm, we recommend using Push.

— Chrome, Use Firebase Cloud Messaging (FCM) with browser.gcm

browser.gcm (permission gcm) connects to legacy Firebase Cloud Messaging HTTP APIs—still supported in extensions but without FCM Topics on that legacy path, and broadcast-to-all-clients semantics unless you filter client-side. See Real-time updates in Extensions for choosing push vs WebSockets vs browser.gcm.

Debug background sync and push in Chrome DevTools

Section titled “Debug background sync and push in Chrome DevTools”

Chrome can log background service events for up to three days, even when DevTools is closed, after you click Record on the relevant panel.

  1. Open DevTools on a page that registers your service worker.

  2. Go to Application → Background services and choose Background sync, Push Messaging, or Notifications (or Periodic Background Sync for periodicsync lifecycle logging as described in Periodic Background Sync).

  3. Click Record, trigger activity on your site, and inspect events in the table (click a row for details).

  4. For Workbox queues, inspect Application → IndexedDB → workbox-background-sync → requests, then force sync via Application → Service Workers with tag workbox-background-sync:<your queue name>.

  5. Stop recording when finished, or leave it running for long-running diagnosis.

Push test messages can also be sent from Application → Service Workers using the Push control, as noted in Debug background services.

  • Treating periodic background sync like background sync—they address upload retries versus prefetch, respectively (Periodic Background Sync).
  • Expecting push to update badges silently in Chrome without a notification (Badging for app icons).
  • Relying on DevTools offline mode to test service worker network behavior (workbox-background-sync).
  • Assuming HTTP 5xx responses retry automatically with BackgroundSyncPlugin without extra plugins.
  • Requesting notification permission immediately on load (notification-on-start).
  • Building new features on Notification Triggers though development has ended (Notification Triggers API).
  1. Install your PWA, register the service worker, and confirm Application → Service Workers shows an active worker.
  2. Test one-off sync: go offline at the OS level, queue a failing POST, restore connectivity, and verify replay via Background sync recording or IndexedDB queue emptying (Retrying requests when back online).
  3. If you use periodic sync, confirm periodicSync.getTags() and engagement requirements (Periodic Background Sync).
  4. For push, verify subscription, permission, and Push Messaging logs; audit Lighthouse notification-on-start if you prompt on load.
  5. You can check automatically in Answerwell (our tool): https://answerwell.org/workspace

If something on this page is wrong or unclear, email yimasynthetic@gmail.com with the page URL and the exact statement you are asking about, and we will correct or clarify it.