Browser extension: detect and subscribe to standard.site publications on ATProto substandard.blog
README.md

substandard #

A Chromium (MV3) browser extension that notices when a page belongs to a standard.site publication on the AT Protocol, and lets you subscribe to it with your own atproto account.

What it does #

  • Detects publications via the authoritative /.well-known/site.standard.publication endpoint, with <link rel="site.standard.publication"> and <link rel="site.standard.document"> head tags as hints. Verification is bidirectional: the well-known endpoint at the publication record's own url must return the record's at-uri.
  • The toolbar icon is always the substandard logo; per-tab status is shown with Chrome's native action badge: grey • while checking, plain green while a verified publication is detected (? on green when signed out, so subscription state is unknown), ✓ on green when subscribed, ! on amber for an unverified candidate or a detection error, x on red when the page is not on standard.site. Non-http pages carry no badge.
  • The popup shows the publication's name, icon, and description, plus the current article when the page has a document record.
  • The popup also carries a per-state status line (src/lib/status.ts), so states that share an icon still read differently: an unverified publisher (e.g. viewing a publication through a third-party reader) is told apart from a detection error, being offline from a record fetch failure, and a failed subscription-list load is called out instead of silently showing a stale Subscribe button.
  • Subscribe/unsubscribe writes site.standard.graph.subscription records to your own PDS. Nothing is stored server-side by this extension.
  • "Open in " split button with a dropdown to pick another reader or set a default. Readers: Standard Reader (standard-reader.app, the default until you pick one), Leaflet, Docs.surf, PDSls.
  • Records and subscription state are cached with short TTLs; the popup's Refresh re-fetches everything, since records can change remotely.

Install #

npm install
npm run package   # build + verify dist/ is loadable

Then in Chrome: chrome://extensions → enable Developer mode → Load unpacked → select the dist/ directory.

The manifest pins the extension ID to degljbilkggdpbobomfbgnellecgbkjj via the key field, so the OAuth redirect URI stays stable across machines. The matching private key (key.pem) is not needed for unpacked loading and stays out of git.

Sign in #

atproto OAuth requires the client to be identified by a publicly hosted metadata file. Ours lives at https://substandard.blog/client-metadata.json (see oauth/ for the file and infra/ for the hosting). The extension requests only the repo:site.standard.graph.subscription scope — it can manage its own subscription records and nothing else.

The sign-in flow runs in a dedicated extension tab (the popup would close when the consent window opens): enter your handle, approve on your PDS, done. Sessions persist in IndexedDB with a non-extractable DPoP key — the same model @atproto/oauth-client-browser uses for web apps — so you stay signed in across browser restarts without re-consenting.

Hosting the site and client metadata #

infra/ contains OpenTofu for a fresh AWS account: a Route53 zone for substandard.blog, an ACM certificate, a private S3 bucket fronted by CloudFront, and the site objects. The bucket serves two things: the Astro-built frontpage from web/dist/ (CloudFront's default_root_object is index.html, so https://substandard.blog/ renders it) and the metadata JSON at /client-metadata.json. The frontpage copy is intentionally PLACEHOLDER-* strings until real wording is written.

The frontpage (and only the frontpage — not the extension) reports analytics to an EU-hosted PostHog project via web/src/components/PostHog.astro. Tracking is cookieless (persistence: "memory"), and the snippet is only included in production builds, so astro dev traffic never reaches PostHog (astro preview serves the production build, so it does).

Build the frontpage before planning or applying — the site objects are read from the build output, and a plan-time precondition fails if web/dist/index.html is missing (otherwise an empty fileset() would silently plan to delete every site object):

npm --prefix web install
npm --prefix web run build
cd infra
tofu init
tofu apply

The first apply blocks on certificate validation until you copy the zone_name_servers output into the NS records at the registrar. Once delegation propagates, the apply finishes on its own (or re-run it).

If the metadata JSON or the frontpage changes, redeploy with scripts/deploy-site.sh — it checks AWS credentials, rebuilds the frontpage, and runs tofu apply (extra arguments are passed through to apply). Then invalidate the CloudFront cache or wait out the TTL. Hashed assets under _astro/ are uploaded with immutable long-cache headers; only index.html and other unhashed files need invalidating. PDSes re-fetch the metadata when clients authenticate.

Development #

npm run check         # typecheck
npm run build         # popup/auth/background build + content-script IIFE build
npm run verify:dist   # check dist/manifest.json and that every referenced file exists
npm run package       # build + verify:dist in one step
npm run dev           # both builds in watch mode; keeps dist/ loadable
npm test              # vitest unit tests (src/lib/*.test.ts; no network)

npm run dev watches both build environments (scripts/dev.mjs). After an edit, reload the extension from chrome://extensions; the popup picks up the new build on next open, and the worker re-injects the content script into open tabs itself (chrome.runtime.onInstalled), since manifest injection only happens at document load and a reload or store update would otherwise leave every open tab orphaned until navigation. The resulting burst of per-tab detection runs is smoothed by a small queue (src/lib/scheduler.ts): a few run at once, the newest request per tab wins, and popup/active-tab requests jump ahead.

./deploy-ext.sh packages a Chrome Web Store release: it refuses a dirty tree, runs the typecheck and tests, asserts package.json and public/manifest.json agree on the version, requires the release tag v<version> to already exist and point at HEAD (the script makes no version decisions and creates no tags), does a clean build plus verify:dist, and zips the contents of dist/ (manifest at the zip root, key field kept so the first store upload preserves the pinned extension ID) into release/substandard-v<version>.zip. Tagging, pushing the tag, and uploading the zip are manual steps.

Lint hooks are configured in prek.toml (prek): whitespace/EOF/JSON hygiene, the typecheck above, and tofu fmt -check for infra/. Run them all with prek run --all-files.

Layout:

  • src/background.ts — service worker: per-tab detection state, toolbar badge states, public reads (records, subscription list)
  • src/content.ts — reads head link tags, reports to the worker
  • src/lib/detection.ts — well-known probing and verification
  • src/lib/icon.ts — state and badge mapping, plus the overscanned base icon render
  • src/lib/atproto.ts — DID/handle resolution, public record fetches
  • src/lib/oauth.ts — OAuth client; extension pages only, never the worker (the browser OAuth client needs window/localStorage)
  • src/popup/ — popup UI; PDS writes happen here via the restored session
  • auth.html, src/auth/ — dedicated sign-in tab
  • oauth/client-metadata.json — the hosted OAuth client identity
  • web/ — Astro project for the substandard.blog frontpage (placeholder copy); npm --prefix web run dev to serve it, npm --prefix web run build to emit web/dist/
  • infra/ — OpenTofu for the frontpage and metadata hosting