Feature Detection vs UA Sniffing: The 2026 Compatibility Methodology

Feature Detection vs UA Sniffing: The Compatibility Methodology

UA sniffing has been unreliable for decades and now works against you. The replacements — @supports, capability checks, UA Client Hints — and the migration plan.

User-Agent sniffing has been unreliable for decades and now works against you — Chromium reduced its UA string in stages from 2022 to 2023, and Firefox and Safari have long capped or frozen parts of the platform detail they report. Code that branches on navigator.userAgent is reading frozen or coarse device, platform, and fine-grained version data, and the string never says whether a feature is present. The replacements are direct and structured: @supports for CSS and capability checks for JavaScript, both supported in every engine, plus User-Agent Client Hints — Chromium-only as of October 2026 — for the rare cases where you genuinely need platform metadata. This guide covers the patterns, the migration plan, and the lint rule that prevents regression.

Why UA sniffing has been unreliable for decades

The User-Agent string is a historical artifact, not a data source. Almost every browser still sends Mozilla/5.0 — per MDN, a token that says the browser is Mozilla-compatible, kept "for historical reasons". Chrome reports AppleWebKit, KHTML, like Gecko, Chrome, and Safari at once, and Edge appends Edg on top of that, to satisfy server-side sniffs written over the decades. Firefox claims Gecko with a fixed Gecko/20100101 trail on desktop. Safari reports AppleWebKit and Safari, a Version token, and a macOS version frozen at 10_15_7.

UA parsers break again and again. The string is unparseable in a forward-compatible way because browsers have repeatedly added tokens to satisfy older servers, and renaming or rearranging tokens would break those same servers. The accumulated result is a sentence written in a language that nobody speaks but every server is required to misunderstand.

What you actually want — does this engine support the feature I am about to use — has nothing to do with the UA string. Feature support is a property of the engine version, the build, and the user's settings (some features can be disabled), and the only authoritative answer is to ask the engine directly.

The UA string's shrinking utility was finally formalized in the platform itself. Chromium's User-Agent Reduction shipped in stages from M101 in 2022 to M110 in 2023, deliberately reducing the string's information content — minor, build, and patch numbers fixed at 0.0.0, OS version and device model frozen, while the major version is still reported accurately. Firefox caps the macOS version it reports at 10.15, and it temporarily froze its Gecko rv: token at 109.0 for Firefox 110 to 119 (restored in Firefox 120) to avoid being misread as Internet Explorer 11. Safari has reported a frozen macOS version for years. As of October 2026, UA sniffing reads platform and fine-grained version data the engines have explicitly stopped maintaining — and it never answered the real question of whether a feature exists.

CSS feature detection — @supports

@supports is Baseline Widely available and has worked across browsers since September 2015. It is the right tool for almost every CSS-side compatibility decision.

The basic form takes a property and value pair:

css
@supports (display: grid) {
  .layout {
    display: grid;
  }
}

The block applies only when the engine recognizes both the property and the value. The inverse path uses not:

css
@supports not (display: grid) {
  .layout {
    display: flex;
  }
}

Combined conditions test multiple capabilities at once:

css
@supports (display: grid) and (gap: 1rem) {
  .layout {
    display: grid;
    gap: 1rem;
  }
}

Putting a CSS function in the value tests function support, not just property support — useful for color spaces, math functions, and the modern CSS function library:

css
@supports (background: color-mix(in oklch, red, blue)) {
  .accent {
    background: color-mix(in oklch, var(--brand), white 20%);
  }
}

The selector form tests selector support, useful for :has() and other selector-level features that engines shipped at different times:

css
@supports selector(:has(*)) {
  .card:has(img) {
    padding-block-start: 0;
  }
}

Anything CSS-detectable should be detected this way. The pattern is durable across engines and browser versions — no string parsing and no version comparison.

JavaScript feature detection

JavaScript needs a small toolbox of patterns because feature shapes vary.

The in operator on a global or prototype is the most direct check for an object's existence:

js
if ('IntersectionObserver' in window) {
  observer = new IntersectionObserver(callback);
}

if (typeof HTMLDialogElement === 'function' && 'showModal' in HTMLDialogElement.prototype) {
  dialog.showModal();
}

The typeof check works for free-standing globals and functions:

js
if (typeof navigator.share === 'function') {
  await navigator.share({ url, title });
}

For constructors, check the constructor itself:

js
if (typeof CSSContainerRule !== 'undefined') {
  // container queries available
}

For methods on existing prototypes, the in form is preferable to method invocation:

js
if ('checkVisibility' in Element.prototype) {
  return el.checkVisibility();
}

A property descriptor probe is necessary in the rare case where a feature adds a new option to an existing method's option bag and the only signal is whether the option is read. Few codebases need this pattern; when needed, it looks like:

js
let optionRead = false;
const probe = Object.defineProperty({}, 'capture', {
  get() { optionRead = true; }
});
window.addEventListener('test', null, probe);
if (optionRead) {
  // event listener options bag is supported
}

The pattern to avoid is invocation as a feature check. Calling an API just to test for it has side effects — network requests, permission prompts, microtask scheduling — and a try/catch wrapper is a poor substitute for asking "is this here." Reserve try/catch for cases where invocation is the only available signal.

The User-Agent reduction in detail

The change to the UA string is worth understanding because it determines what UA-parsing code is now reading.

Chromium reduced the UA across versions. M101 fixed the minor, build, and patch numbers at 0.0.0; M107 reduced the desktop platform string and M110 the Android one. The reduced UA now reports the accurate major version, a minor / build / patch fixed at 0.0.0, and a coarsened platform string (for example Windows NT 10.0, Intel Mac OS X 10_15_7, or Android 10; K in place of the real OS version and device model). A major-version branch like if (chromeVersion < 100) still evaluates correctly, but a branch keyed on a build number reads 0.0.0, and a branch keyed on OS version or device model reads a fixed placeholder regardless of the user's actual system.

Firefox still reports its current major version in the Firefox/NNN token. The rv: Gecko token was held at 109.0 for Firefox 110 to 119 and has tracked the release again since Firefox 120, so code that parsed rv: instead of Firefox/ misread versions during that window. The macOS version Firefox reports is capped at 10.15.

Safari reports a macOS version frozen at 10_15_7 regardless of the installed macOS, so any platform-version branching for Safari on the Mac reads a placeholder.

The collective implication: any UA-parsing branch in your codebase that reads minor version, build number, or precise platform detail is now reading frozen or coarse data and silently picking the wrong code path. The bug surface is invisible — the code does not throw, the wrong branch just executes.

User-Agent Client Hints — when you genuinely need device metadata

For the cases where you actually need structured platform information, User-Agent Client Hints is the structured replacement.

The client side exposes navigator.userAgentData:

js
const ua = navigator.userAgentData;
if (ua) {
  console.log(ua.brands);    // [{brand: 'Chromium', version: '120'}, ...]
  console.log(ua.mobile);    // true / false
  console.log(ua.platform);  // 'Windows' / 'macOS' / 'Linux' / 'Android' / 'iOS'
}

These are low-entropy values — coarse data the engine will share without explicit opt-in. The mobile flag and platform string are the most useful pieces.

For more detailed information, getHighEntropyValues() returns a Promise:

js
const detail = await navigator.userAgentData.getHighEntropyValues([
  'model', 'platformVersion', 'architecture', 'fullVersionList'
]);

High-entropy values are gated by browser policy and can be denied; do not assume they are available.

The server side receives structured headers by default: Sec-CH-UA, Sec-CH-UA-Mobile, and Sec-CH-UA-Platform are sent on HTTPS requests from browsers that implement Client Hints, unless a Permissions Policy restricts them. The server opts into more detail by responding with Accept-CH: Sec-CH-UA-Platform-Version, Sec-CH-UA-Model, Sec-CH-UA-Arch and the client sends those headers on subsequent requests.

Cross-engine support is limited to one engine. As of October 2026, User-Agent Client Hints and navigator.userAgentData are implemented only in Chromium-based browsers (Chrome, Edge, and other Blink browsers); Firefox and Safari do not implement them, and MDN marks the API as not Baseline. For cross-engine code, treat navigator.userAgentData as a Chromium-only enhancement and fall back to feature detection when it is not present.

Patterns for the rare cases where you must detect a browser

Some compatibility questions cannot be phrased as "does X exist." Four patterns capture most of the legitimate cases.

A bug-specific workaround is appropriate when an engine has a known, undisputed bug, the bug has a public tracker URL, and the workaround is documented with a removal trigger. The right format is a comment that names the engine, the bug, and the condition for removal.

A vendor-specific behavior workaround handles the case where a third-party SDK or platform feature only works on a specific engine — for example, a hardware API that only Chromium ships. Use User-Agent Client Hints' brands array to detect Chromium specifically, redirect or warn affected users, and record the dependency in the team's compatibility-policy doc.

A native feature handoff — deep-linking to a native app on iOS, Android, or desktop — is genuinely platform-driven. The platform field of navigator.userAgentData is the right input where it exists (Chromium-based browsers only, so iOS still needs a fallback); the platform field of UA Client Hints is the structured replacement for parsing the UA string for "iOS" or "Android."

A PWA-specific behavior — a feature that fires only in some browsers, like beforeinstallprompt in Chromium — should not be gated on engine detection. Gate on the event firing or the API existing. The right pattern is feature detection of the API itself, not browser detection of the engine that supports it.

If you cannot phrase the check as "does X exist" or "does Y work," you usually do not need a browser branch. UA-driven branching for non-platform reasons (analytics buckets, A/B test cohorts) belongs in analytics code, not in feature paths.

Migration — removing navigator.userAgent code

A focused migration retires UA sniffing as a class.

Step one is the audit. Grep the codebase for navigator.userAgent, navigator.appVersion, and document.documentMode (the legacy IE-only signal). Each match is a future bug — the surrounding logic was written against a UA shape that may no longer exist.

Step two is the per-match analysis. For each match, ask: what feature is this branch gating? The answer is usually a specific API or CSS property. Replace the UA check with the corresponding feature detection — @supports for CSS, 'X' in window or typeof X === 'function' for JavaScript.

Step three handles the residual cases. For checks that are genuinely platform-driven (mobile vs desktop, iOS vs Android for native deep-linking), use navigator.userAgentData if it provides what you need. For high-entropy data not available on all engines, accept that the branch is wrong some of the time and degrade gracefully.

Step four is the lint rule. Add an ESLint rule that flags new navigator.userAgent reads. No dedicated plugin is needed; ESLint's built-in no-restricted-properties rule covers it:

json
{
  "rules": {
    "no-restricted-properties": ["error",
      { "object": "navigator", "property": "userAgent", "message": "Use feature detection instead of UA sniffing." },
      { "object": "navigator", "property": "appVersion", "message": "Use feature detection instead of UA sniffing." }
    ]
  }
}

The rule matches the navigator identifier, so pair it with a grep in review for aliased access such as window.navigator.userAgent. Without the lint rule, UA sniffing can return as soon as someone copies an old snippet.

Step five is the polyfill cleanup. Polyfills that were targeted by UA sniffing are now mistargeted because the UA's platform and fine-grained version details are frozen. Remove the polyfills whose feature detection has been Widely available for years; the polyfill is dead weight in every modern user's bundle, and the legacy users it was meant to serve are no longer detectable through UA anyway.

Verify the bundle delta and the error-rate dashboards in canary before rolling out. The rare case where UA sniffing was load-bearing — typically a workaround that masked an engine bug — needs a feature check or a documented engine-specific behavior comment to replace it.

Topic integration — how this connects to Baseline and Interop

The methodology stack fits together in four layers.

Baseline status answers "should I adopt this feature" — the policy decision at code-review time. Baseline is defined by the WebDX Community Group and gives the team a shared vocabulary for whether a feature is ready to use.

Interop answers "which features are browser makers working to make interoperable this year" — the architectural-planning signal that shows where cross-browser gaps are being worked on. Closing those gaps can move a Limited availability feature toward Newly available; Widely available still comes only 30 months after the Newly available date.

Feature detection answers "is this feature here right now" — the runtime decision in code. CSS uses @supports, JavaScript uses capability checks.

User-Agent Client Hints, where supported, answers "what platform am I on" — the rare case where a check is genuinely platform-driven, not feature-driven.

UA sniffing answers nothing reliable. It belongs in archived code commits, not in production paths.

The result is a compatibility methodology that scales across new browser versions without code changes. New engines that respect web standards inherit the @supports and capability-check answers automatically. New versions of existing engines rarely require changes because the checks are about the platform, not the brand. The opposite of UA sniffing's perennial maintenance burden.

Migration priorities for the next planning cycle

  • Grep the codebase for navigator.userAgent, navigator.appVersion, and document.documentMode — each match is a candidate for replacement with feature detection
  • Pick the highest-traffic UA-sniffing branch and replace it with @supports or a JavaScript capability check; verify in canary before merging
  • Add an ESLint rule that flags new navigator.userAgent reads — without the lint rule, UA sniffing returns
  • For genuinely platform-driven checks, migrate to navigator.userAgentData with a feature-detection fallback for Firefox, Safari, and other engines that do not implement it
  • Remove polyfills whose UA-targeted serving is now wrong because the UA's platform and fine-grained version details are frozen — measure the bundle delta and report it in the PR
  • Document the decision in the team's compatibility-policy doc: feature detection at runtime, Baseline at code review, Interop for convergence planning, no UA sniffing
Project Inquiry