Detecting browser capabilities
suggest changeWeb-platform features and their behavior can differ among browsers and versions. In most cases, test for the capability the application needs instead of inferring it from a browser name or user-agent string.
if ("geolocation" in navigator) {
// The API exists; calls may still fail because of permissions or policy.
} else {
// Provide an alternative experience.
}
Feature presence does not guarantee that an operation will succeed. Permissions, secure-context requirements, device capabilities, and runtime errors must still be handled.
Browser detection is occasionally appropriate for browser-specific instructions or a workaround for a confirmed browser defect. User-agent strings can be spoofed and often identify more than one browser, so parsing them is fragile. If detection is unavoidable, keep the test narrow and document why it is needed.
Modernizr can help when an application needs a large set of declarative feature tests.