From 61cdc95b8a9dfb59350353d127a75859018a67ac Mon Sep 17 00:00:00 2001 From: David Nguyen Date: Fri, 20 Nov 2026 13:12:28 +0700 Subject: [PATCH 1/5] fix(pwa): verify connectivity and auto-restore offline page --- public/offline.html | 117 +++++++++++++++++++++++++++++++++++++++----- 1 file changed, 106 insertions(+), 11 deletions(-) diff --git a/public/offline.html b/public/offline.html index fa3b43a2..7b43d2ce 100644 --- a/public/offline.html +++ b/public/offline.html @@ -18,7 +18,9 @@ button { appearance: none; border: 0; border-radius: 13px; background: #e11d48; color: white; font: inherit; font-weight: 650; padding: 13px 25px; min-height: 48px; cursor: pointer; } button:focus-visible { outline: 3px solid #fda4af; outline-offset: 4px; } button:hover { background: #be123c; } - .note { display: block; margin-top: 18px; color: #aaaab6; font-size: 12px; } + .connection-state { display: block; min-height: 20px; margin-top: 14px; color: #fda4af; font-size: 13px; } + .note { display: block; margin-top: 12px; color: #aaaab6; font-size: 12px; } + button:disabled { cursor: progress; opacity: .75; } @media (prefers-reduced-motion: no-preference) { button { transition: background .15s ease; } } @@ -31,18 +33,19 @@

You're offline

Live radio needs an internet connection. Reconnect to keep listening.

+ Waiting for a connection… Live stations cannot play offline. From 14dfd56b034e06b67d605a52aa5a1ee8d9e2c86a Mon Sep 17 00:00:00 2001 From: David Nguyen Date: Fri, 20 Nov 2026 13:12:41 +0700 Subject: [PATCH 2/5] fix(pwa): refresh precached offline page on service worker update --- public/service-worker.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/public/service-worker.js b/public/service-worker.js index 16d75eef..3ec7146e 100644 --- a/public/service-worker.js +++ b/public/service-worker.js @@ -4,7 +4,7 @@ */ const OFFLINE_SCOPE_KEY = encodeURIComponent(new URL(self.registration.scope).pathname); const OFFLINE_CACHE_PREFIX = 'onair-offline-shell-' + OFFLINE_SCOPE_KEY + '-v'; -const OFFLINE_CACHE_NAME = OFFLINE_CACHE_PREFIX + '1'; +const OFFLINE_CACHE_NAME = OFFLINE_CACHE_PREFIX + '2'; const OFFLINE_URL = new URL('offline.html', self.registration.scope).href; self.addEventListener('install', event => { From b45a855453f6fb6e4357eaef9198a5864a4ea3b3 Mon Sep 17 00:00:00 2001 From: David Nguyen Date: Fri, 20 Nov 2026 13:13:02 +0700 Subject: [PATCH 3/5] test(pwa): assert refreshed offline cache and reconnect safeguards --- tests/pwa-install-shell.test.mjs | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/tests/pwa-install-shell.test.mjs b/tests/pwa-install-shell.test.mjs index b0929742..4080b108 100644 --- a/tests/pwa-install-shell.test.mjs +++ b/tests/pwa-install-shell.test.mjs @@ -13,6 +13,7 @@ function workerHarness(source) { const cacheKeys = [ 'onair-offline-shell-%2Fpr-preview%2Fpr-2%2F-v0', 'onair-offline-shell-%2Fpr-preview%2Fpr-2%2F-v1', + 'onair-offline-shell-%2Fpr-preview%2Fpr-2%2F-v2', 'onair-offline-shell-%2Fpr-preview%2Fpr-3%2F-v0', 'some-other-app', ]; @@ -22,7 +23,7 @@ function workerHarness(source) { add: async request => { saved.push(request.url || request); }, }; const caches = { - open: async name => { assert.equal(name, 'onair-offline-shell-%2Fpr-preview%2Fpr-2%2F-v1'); return cache; }, + open: async name => { assert.equal(name, 'onair-offline-shell-%2Fpr-preview%2Fpr-2%2F-v2'); return cache; }, keys: async () => cacheKeys, delete: async name => { deleted.push(name); return true; }, match: async url => url === 'https://radio.example/pr-preview/pr-2/offline.html' @@ -79,7 +80,10 @@ test('service worker caches only the noindex offline explanation, not stations o assert.deepEqual(worker.saved, ['https://radio.example/pr-preview/pr-2/offline.html']); assert.doesNotMatch(source, /self\.skipWaiting\(|self\.clients\.claim\(|cache\.put\(/); await worker.run('activate'); - assert.deepEqual(worker.deleted, ['onair-offline-shell-%2Fpr-preview%2Fpr-2%2F-v0']); + assert.deepEqual(worker.deleted, [ + 'onair-offline-shell-%2Fpr-preview%2Fpr-2%2F-v0', + 'onair-offline-shell-%2Fpr-preview%2Fpr-2%2F-v1', + ]); for (const request of [ { mode: 'no-cors', method: 'GET', destination: 'audio', url: 'https://stream.example/live.mp3' }, @@ -124,4 +128,9 @@ test('offline HTML explicitly refuses offline radio, is noindex and is self-cont assert.doesNotMatch(html, /<(?:script|link)[^>]+(?:src|href)=["']https?:\/\//i); assert.match(html, /env\(safe-area-inset-bottom\)/); assert.match(html, /window\.location\.reload\(\)/); + assert.match(html, /getRegistration\?\.\(\)/); + assert.match(html, /brand\/site\.webmanifest/); + assert.match(html, /aria-live="polite"/); + assert.match(html, /cache: 'no-store'/); + assert.match(html, /document\.addEventListener\('visibilitychange'/); }); From aeb13d0b5149b7cc285d5790f1bd190926220c98 Mon Sep 17 00:00:00 2001 From: David Nguyen Date: Fri, 20 Nov 2026 13:13:55 +0700 Subject: [PATCH 4/5] test(pwa): exercise online recovery, backoff, manual retry and preview scope --- tests/pwa-reconnect.test.mjs | 154 +++++++++++++++++++++++++++++++++++ 1 file changed, 154 insertions(+) create mode 100644 tests/pwa-reconnect.test.mjs diff --git a/tests/pwa-reconnect.test.mjs b/tests/pwa-reconnect.test.mjs new file mode 100644 index 00000000..05e184b0 --- /dev/null +++ b/tests/pwa-reconnect.test.mjs @@ -0,0 +1,154 @@ +import test from 'node:test'; +import assert from 'node:assert/strict'; +import { readFile } from 'node:fs/promises'; +import { runInNewContext } from 'node:vm'; + +const read = path => readFile(new URL('../' + path, import.meta.url), 'utf8'); + +async function offlinePageHarness({ reachable = false, hidden = false, validManifest = true } = {}) { + const html = await read('public/offline.html'); + const script = html.match(/