User-agent detection
suggest changeAvoid parsing navigator.userAgent to decide whether a feature is available. User-agent strings are inconsistent, can be spoofed, and commonly contain compatibility tokens for other browsers. Prefer feature detection and handle failures at the point where an API is used.
Top-level await in the sample requires a module.
if (typeof navigator.share === "function") {
await navigator.share({ title: document.title, url: location.href });
} else {
// Offer a copy-link fallback.
}
Browser identification may still be appropriate for browser-specific help text, analytics, or a narrowly scoped workaround for a verified browser defect. Keep such logic separate from capability checks, avoid assuming that a browser name implies a feature, and remove workarounds when they are no longer needed.
When a platform provides structured user-agent client hints, they can reduce brittle string parsing, but availability and disclosed information vary. Treat both client hints and the traditional user-agent string as hints rather than authoritative identity or security signals.