diff --git a/docs/PWA.md b/docs/PWA.md index afe58e07..e6b4a116 100644 --- a/docs/PWA.md +++ b/docs/PWA.md @@ -14,6 +14,11 @@ This is an **online-first app shell**, not an offline radio player. - The worker pre-caches **only** `offline.html`, a small static, noindex, self-contained explanation. Navigation requests go to the network first. On a network failure, the worker displays the translated offline explanation. + The fallback page listens for browser connectivity changes and also probes the + same-origin, deployment-scoped web manifest with a 5-second timeout and + backoff (3 to 15 seconds). It reloads the **original URL** only after a valid + network response, does not loop-refresh while offline, and pauses background + probes while hidden. The manual Retry button uses the same verification. - There is **no audio cache**: MP3/AAC, .m3u8 playlists, HLS segments, provider requests, API, JS, CSS, search index JSON and all real station HTML stay network-only. A stream always requires a current online connection. @@ -41,7 +46,12 @@ tabs; test on the actual device before marking #340 or #346 complete. - [ ] Install on Android Chrome and open the app from its launcher. - [ ] Add to Home Screen on Safari iOS, test lock-screen/audio interruptions. - [ ] With the app open, go offline then navigate: see the offline explanation; - retry after restoring connection should fetch a fresh live page. + restore connection and verify automatic recovery to the same page without + pressing Retry. Also verify Retry works and no repeated reloads occur + while disconnected, including when the browser omits an online event. +- [ ] Repeat the recovery test on a station deep link and on a + `/pr-preview/pr-N/` deployment: its connectivity probe must stay within + the active Pages scope. A browser reload must leave the player paused. - [ ] Use DevTools Application → Cache Storage: **only** `offline.html` is precached; no station catalog, stream segments or signed URLs. - [ ] Update the worker: no forced reload, old audio continues, next visits @@ -49,5 +59,6 @@ tabs; test on the actual device before marking #340 or #346 complete. - [ ] `npm test`, `npm run generate:site`, SEO/GA4 noindex and GitHub Pages subpath validations, mobile light/dark and safe-area smoke tests. -The automated tests verify worker/cache policy and manifest URL resolution. +The automated tests verify worker/cache policy, manifest URL resolution, and +offline-page automatic recovery, polling backoff and preview-scoped probes. Physical iOS/Android QA remains **not run** until independently documented. 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. 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 => { 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'/); }); 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(/