feat(ua): expose low-entropy user-agent as --const-ua-* (plugin + head) - #13
Merged
Conversation
Add a `ua` global plugin and matching `head` constants that surface the device/browser identity JS can read but CSS can't, as five write-once custom properties: - --const-ua-platform macos/windows/linux/android/ios/chromeos/unknown - --const-ua-browser chrome/edge/firefox/safari/opera/samsung/unknown - --const-ua-engine blink/gecko/webkit/unknown - --const-ua-version browser major (0 if unknown) - --const-ua-mobile 1/0 A shared reader (src/core/ua.ts) prefers structured UA Client Hints (navigator.userAgentData, Chromium) and falls back to a best-effort userAgent-string sniff on Firefox/Safari. Low-entropy only — no getHighEntropyValues, device model, full version, or architecture — so it adds no fingerprinting surface beyond what request headers already expose. The same five consts are also written synchronously by the head entry for FOUC-safe, pre-paint branching (@container style(--const-ua-engine: webkit)). Typed mode registers the strings as <custom-ident>, the numbers as <integer>. Includes demosite gallery card + docsite demo, README/llms.txt/reference sync, unit tests for the reader, and a patch version bump (0.7.8).
✅ Deploy Preview for prop-for-that ready!
To edit notification comments on pull requests, go to your Netlify project configuration. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What
Adds a
uaglobal plugin and matchingheadconstants that surface the device/browser identity JS can read but CSS can't, as five write-once custom properties:--const-ua-platformmacos/windows/linux/android/ios/chromeos/unknown--const-ua-browserchrome/edge/firefox/safari/opera/samsung/unknown--const-ua-engineblink/gecko/webkit/unknown--const-ua-version0if unknown)--const-ua-mobile1on a phone-class device, else0Now CSS can branch on the client with no JS and no media query:
How
src/core/ua.ts— shared reader. Prefers structured UA Client Hints (navigator.userAgentData, Chromium), falls back to a best-effortuserAgent-string sniff on Firefox/Safari. SSR-safe.src/plugins/ua.ts— global source,constcadence, typed (<custom-ident>strings,<integer>numbers). Registered inplugins/index.ts+loaders.tssoautolazy-loads it.src/head.ts— writes the same five consts synchronously → FOUC-safe, pre-paint branching (dual-availability, likenav-type). Shared code split into theheadand plugin chunks; coreindex.jsstays lean.Privacy
Low-entropy only — no
getHighEntropyValues, device model, full version, or architecture. Everything here is already sent in request headers, so it adds no fingerprinting surface beyond what the server already sees. Off Chromium the string fallback is best-effort — hints, not identity.Demos & docs
uacard at the end of "Every source, at a glance" (string idents rendered via the same style-query trick asnav-type)./demos/ua/page (chips light up for the detected OS / browser / engine), plusreference/plugins,getting-started, README, andllms.txtkept in sync.Verification
npm run typecheckclean · 110 unit tests pass (6 new for the reader) ·npm run buildsucceedshead.*and the plugin chunks, not in coreindex.js:rootcomputesplatform=macos, browser=chrome, engine=blink, version=148, mobile=0; gallery labels and docs chips highlight the right valuesVersion bumped 0.7.7 → 0.7.8 (additive → patch) with a
CHANGELOG.mdentry.