Skip to content

Works offline: detect it from the service worker, tag listings, filter by it - #21

Merged
ralyodio merged 1 commit into
masterfrom
feat/offline-feature
Oct 6, 2026
Merged

ralyodio merged 1 commit into
masterfrom
feat/offline-feature

Conversation

@ralyodio

@ralyodio ralyodio commented Oct 6, 2026

Copy link
Copy Markdown
Contributor

Anthony asked: when a listing is created, work out whether the PWA works offline and tag it as a feature the store can filter by.

Detection (apps/web/src/inspect.js)

  • serviceWorkerUrls() parses navigator.serviceWorker.register('<url>') (minified and new URL(...) forms too). Only same-origin URLs count.
  • detectOffline() tries candidates in this order: what the page registers, the manifest's serviceworker.src, one small same-origin registration script (for example vite-plugin-pwa's registerSW.js), then /sw.js, /service-worker.js, /serviceworker.js and /sw.min.js. It makes at most 4 fetches through safeFetch, each capped at 1 MB and 5 s. An SPA's catch-all index.html is not accepted as a worker.
  • classifyServiceWorker() returns offline for Workbox, or for a fetch handler that uses the Cache API. A pass-through fetch handler, a push-only worker or no worker at all gives false. The reason is stored.
  • New recommended check: "Works offline".

Storage

Migration 0011_app_features.sql adds apps.features text[] with a GIN index, plus offline_reason and features_checked_at. These are set on submit, on refresh, on the saasrow import, and during release-detect's daily re-read. A new daemon job, feature-backfill, re-inspects 6 never-checked listings every 2 minutes.

Surfaces

  • GET /api/v1/apps?feature=offline (alias offline=1). An unknown feature returns 400.
  • Browse has a "Works offline" chip that keeps q, category, sort and publisher. The home page links to the filter. Cards and the details page show a tag. shape() now includes features, offline and offline_reason.
  • CLI 0.6.0: pwamart search|browse --offline. MCP 0.6.0: search_apps takes feature or offline.
  • sw.js VERSION is bumped to v5.

Tests

  • Unit tests in test/offline.test.js cover the classifier and the URL parser.
  • API tests: the fixture's notes app is offline-capable and todo only passes requests through. The tests check the filter, the browse chip, the tags and the backfill. All 94 pass against Postgres 16.

🤖 Generated with Claude Code

…r by it

The inspector now finds the app's service worker (the URL the page registers,
the manifest's serviceworker.src, a small linked registration script, then
/sw.js, /service-worker.js, /serviceworker.js, /sw.min.js), fetches it with
safeFetch (same origin, 1 MB, 5 s) and classifies it: offline when it is
Workbox or has a fetch handler that uses the Cache API. A new recommended
check "Works offline" says why when it is not.

- migration 0011: apps.features text[] (GIN), offline_reason, features_checked_at
- set on submit, refresh, saasrow import and release-detect's daily re-read
- daemon job feature-backfill: 6 never-checked listings every 2 minutes
- ?feature=offline on /api/v1/apps and /apps; a Works offline chip on browse
  (keeps q, category, sort, publisher), a link on home, a tag on cards and the
  details page; shape() carries features, offline, offline_reason
- CLI 0.6.0: search/browse --offline; MCP 0.6.0: search_apps feature/offline
- sw.js VERSION v5

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@ralyodio
ralyodio merged commit bba5430 into master Oct 6, 2026
3 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant