The window.navigator object contains information about the user's browser vendor, operating system, network connection status, hardware concurrency, geolocation, and clipboard access.
flowchart TD
NavObj["window.navigator"] --> Hardware["Hardware: hardwareConcurrency, deviceMemory"]
NavObj --> Network["Network Status: onLine, connection"]
NavObj --> WebAPIs["Web APIs: clipboard, geolocation, serviceWorker"]
| Property / API | Type | Description |
|---|---|---|
navigator.onLine |
Boolean | Returns true if browser is connected to network. |
navigator.userAgent |
String | Browser user-agent header string. |
navigator.hardwareConcurrency |
Number | Count of logical CPU core processors available. |
navigator.clipboard |
Object | Async Clipboard API for reading/writing system clipboard. |
navigator.geolocation |
Object | Location API for retrieving user GPS coordinates. |
navigator.language |
String | Preferred browser UI language ("en-US"). |
// Demonstrating Navigator API inspections and Async Clipboard
// 1. Inspecting Hardware and Network Status
console.log(`Logical CPU Cores: ${navigator.hardwareConcurrency || "Unknown"}`);
console.log(`User Preferred Language: ${navigator.language}`);
console.log(`Network Online Status: ${navigator.onLine}`);
// Listen for network connectivity changes
window.addEventListener("online", () => console.log("Network Re-connected!"));
window.addEventListener("offline", () => console.log("Network Connection Lost!"));
// 2. Modern Async Clipboard API (Copy Text)
async function copyToClipboard(textToCopy) {
try {
await navigator.clipboard.writeText(textToCopy);
console.log(`Text copied to clipboard: "${textToCopy}"`);
} catch (err) {
console.error(`Failed to copy: ${err.message}`);
}
}
copyToClipboard("KodSolution Modern JS Tutorial");
navigator.userAgent to detect browser capabilities. Use feature detection (if ("clipboard" in navigator)) instead of user-agent string sniffing.https:// or localhost).navigator.clipboard.readText() requires explicit user permission prompts.How do you check if the user's device is currently connected to the Internet using navigator?
Sign in to track your learning journey, earn industry-recognized certificates, and join our elite developer community.
Quick Access With
Experiment with the code from this lesson in our interactive playground.