Skip to content
Tutorials Center
My learning

Topics

JavaScript Reference ยท Browser and Web APIs

The navigator object

Reference for window.navigator: language, onLine, hardwareConcurrency, maxTouchPoints, userAgent and feature detection for clipboard, share, geolocation and more.

window.navigator describes the browser and the device it runs on, and it is the entry point to many Web APIs: navigator.clipboard, navigator.geolocation, navigator.serviceWorker, navigator.mediaDevices, navigator.share() and navigator.sendBeacon().

Its information properties (language, connection status, number of CPU cores, touch points) are useful for adapting a page. Its oldest property, userAgent, is the one to avoid: it is long, messy and now deliberately reduced by browsers. For capabilities, test whether the feature itself exists instead of guessing from the browser name.

JavaScript
console.log(navigator.language);          // "en-US"
console.log(navigator.onLine);            // true or false
console.log("share" in navigator);        // feature detection

Try it

Read the common properties
Feature detection and online/offline events

Syntax

JavaScript
navigator.propertyName
navigator.methodName(args)

Common properties

Name Description
language The user's preferred language as a BCP 47 tag, such as "en-US".
languages Array of preferred languages, most preferred first.
onLine false when the browser is certain it has no network, otherwise true.
cookieEnabled Whether cookies can be set.
hardwareConcurrency Number of logical processor cores available to the browser.
maxTouchPoints Maximum simultaneous touch points the device supports; 0 for none.
deviceMemory Approximate RAM in GB (rounded). Chromium-based browsers only.
userAgent The browser's identification string. Do not parse it for features.
userAgentData Structured browser information (brands, mobile, platform). Chromium only.
webdriver true when the browser is controlled by automation.
platform Deprecated operating-system string. Avoid.

Common methods and objects

Name Description
clipboard The asynchronous Clipboard API.
geolocation Access to the device's position, after permission.
mediaDevices Cameras and microphones through getUserMedia().
serviceWorker Registers service workers.
storage estimate() and persist() for storage quota.
sendBeacon(url, data) Queues a small POST request that survives page unload. Returns a boolean.
share(data) Opens the system share sheet. Needs a user gesture and a secure context.
vibrate(pattern) Vibrates the device (not on iOS).
permissions.query() Reads the permission state of a feature.

Usage notes

  • Detect features, not browsers. Write if ("share" in navigator) or if (navigator.clipboard). User-agent sniffing breaks when browsers change their strings.
  • userAgent is intentionally vague. Browsers freeze or reduce details like minor versions and device models. Use it only for logging or support requests.
  • onLine can lie in one direction. false is reliable; true only means a network interface is connected, not that your server is reachable. Check with a real request.
  • Secure contexts only. Many APIs (clipboard, share, serviceWorker, mediaDevices) exist only on HTTPS pages (and localhost). Their absence can mean the page is not secure.
  • Permissions. Geolocation, camera and similar features show a prompt and may be denied. Always handle errors.
  • Privacy. Values such as hardwareConcurrency and deviceMemory add to a device fingerprint. Browsers may reduce their precision; do not depend on exact values.
  • Language is not location. navigator.language is the user's interface preference. Use Intl to format numbers and dates for it.
  • Touch is not a device type. maxTouchPoints > 0 is true on many laptops. Support both mouse and touch.
  • Sandboxed previews. Some APIs (clipboard, geolocation) are blocked in sandboxed iframes, so the example above only checks that they exist.

Browser support

The core properties (language, languages, onLine, cookieEnabled, hardwareConcurrency, maxTouchPoints) and sendBeacon() work in all current browsers. deviceMemory, userAgentData and vibrate() are limited to some browsers, and each newer API has its own support, so check a compatibility table for the feature you need.