Application Hands-On 5

🔬 Background Services Lab

Welcome to the Background Services lab! In this hands-on session you'll use the Application panel to inspect, debug, and interact with browser background services. Each exercise gives you a specific task — complete them all to master the Application panel's background services section.

⚙️ Setup

  1. Open DevTools (F12) and go to the Application panel
  2. In the sidebar, expand Background services
  3. Start the record button (⏺) in each section before interacting with the exercises
  4. Keep the Console open in a split view so you can see logs too

Exercise 1: Back/Forward Cache Detective 🔍

Easy

Goal: Understand which pages are bfcache-eligible and which aren't.

Tasks:

💡 Hint

The "bad" page uses beforeunload and an open WebSocket — both block bfcache. The test in DevTools lists each blocker individually.

✅ Expected Answer

bfcache-good.html: Should be eligible (no blockers). State (counter, timer) is preserved when navigating back.

bfcache-bad.html: Not eligible. Blockers include: beforeunload event listener, and (if toggled on) an active WebSocket connection.

Exercise 2: Background Sync Spy 🕵️

Medium

Goal: Register, observe, and manually trigger background sync events.

Tasks:

💡 Hint

When offline, sync.register() still succeeds — the browser stores the tag and fires the sync event as soon as connectivity returns. You can also fire it manually from the Service Workers section.

✅ Expected Answer

The Background Sync panel shows events with tags like sync-msg-{timestamp}. When offline, the sync is queued. When back online, the browser fires the sync event and you see the event appear in the timeline. Manual trigger from SW panel also fires the event.

Exercise 3: Notification Inspector 🔔

Medium

Goal: Send notifications, observe them in DevTools, and understand tags.

Tasks:

unknown



💡 Hint

When two notifications share the same tag, the second one replaces the first. Different tags stack as separate notifications.

✅ Expected Answer

Same-tag notifications replace each other (only the latest is visible). Different-tag notifications all appear separately. DevTools Notifications panel shows notificationdisplay, notificationclick, and notificationclose events with their tags, titles, and timestamps.

Exercise 4: Push Messaging Lab 📬

Hard

Goal: Subscribe to push, examine the subscription, and simulate push messages from DevTools.

Tasks:

No active subscription
💡 Hint

The Push input in the Service Workers section sends a simulated push event to the SW. The SW's push event handler receives the text you typed and can show a notification. After unsubscribing, pushing still works from DevTools (the push event goes to the SW regardless of subscription state).

✅ Expected Answer

The subscription shows an endpoint URL (e.g., https://fcm.googleapis.com/...) and encryption keys (p256dh, auth). Simulating a push from DevTools Service Workers panel fires the push event and shows a notification. Even after unsubscribing, the DevTools push button still fires the event because it bypasses the push service.

Exercise 5: Speculative Loads Inspector 🔮

Medium

Goal: Add speculation rules and observe them in the Application panel.

Tasks:



Links for speculation:

bfcache-good.html bfcache-bad.html Application Home
💡 Hint

In the Speculative Loads panel, each rule shows its type (prefetch/prerender), the URLs it applies to, and the current status (Not triggered, Running, Ready, or Failure). Prefetched resources appear in the Network panel with a special Purpose: prefetch header.

✅ Expected Answer

The panel lists each speculation rule with its type and target URLs. Dynamic rules appear when added and disappear when removed. Prerender rules show a full page load in a hidden renderer, while prefetch only downloads HTML. In the Network panel, prefetched requests have the type "prefetch".

Exercise 6: Reporting API Observer 📊

Easy

Goal: Trigger browser reports and observe them in the Application panel.

Tasks:

0 reports
💡 Hint

Deprecation reports are generated when using APIs the browser considers deprecated. ReportingObserver captures these in JavaScript. The Console also shows deprecation warnings separately.

✅ Expected Answer

Clicking "Trigger Deprecation" uses deprecated APIs (synchronous XHR, etc.) which generate deprecation reports. These appear in the Console as warnings and are captured by ReportingObserver. The Application panel's Reporting API section shows the collected reports with type, URL, and body details.

Exercise 7: Service Worker Lifecycle Master 🎓

Hard

Goal: Understand the SW lifecycle using the Application panel's Service Workers section.

Tasks:

💡 Hint

The service worker on this page uses skipWaiting() and clients.claim(), so it activates immediately without waiting. "Update on reload" forces a SW update on every page refresh — useful for development but not for production.

✅ Expected Answer

Status is "activated and is running". Clicking Update installs a new version (if the file changed). skipWaiting() causes immediate activation. Unregister removes the SW but it re-registers on refresh because the page script calls navigator.serviceWorker.register(). Push/Sync/Periodic Sync inputs let you manually fire corresponding events on the SW.

🏆 Bonus Challenge: Full Investigation

Hard

Combine everything you've learned! Perform a full background services investigation:

Tasks:

💡 Pro Tips