JavaScript Browser Information
Learn how to utilize JavaScript to obtain detailed insights into browser behavior and environment. This comprehensive guide covers user agent information, browser details, screen dimensions, geolocation data, cookie operations, online/offline status, timezone, language settings, mobile device detection, storage availability, web workers support, media capabilities, battery status, device memory, hardware concurrency, gamepad detection, VR/AR device information, microphone and camera access, and Bluetooth device details.
Section 1: User Agent Information
Section 2: Browser Information
// Browser Information
const appName = navigator.appName; // The name of the browser
const appVersion = navigator.appVersion; // The version of the browser
const platform = navigator.platform; // The platform (e.g., Win32, Linux x86_64)
console.log('Browser Name:', appName);
console.log('Browser Version:', appVersion);
console.log('Platform:', platform);
Section 3: User Agent Information (Simplified)
Section 4: Screen Information
Section 5: Geolocation Information
// Geolocation Information
if ('geolocation' in navigator) {
navigator.geolocation.getCurrentPosition(function(position) {
const latitude = position.coords.latitude;
const longitude = position.coords.longitude;
console.log('Latitude:', latitude);
console.log('Longitude:', longitude);
});
} else {
console.log('Geolocation is not available in this browser.');
}
Section 6: Cookie Operations
Section 7: Online/Offline Status
Section 8: Timezone Information
Section 9: Language and Locale Information
Section 10: Mobile Device Detection
Section 11: Storage Availability
Section 12: Web Workers Support
Section 13: Media Capabilities
Section 14: Battery Information
Section 15: Device Memory Information
Section 16: Hardware Concurrency Information
Section 17: Gamepad Information
Section 18: VR/AR Device Information
Section 19: Microphone and Camera Access
// Microphone and Camera Access
navigator.mediaDevices.enumerateDevices()
.then(devices => {
const audioDevices = devices.filter(device => device.kind === 'audioinput');
const videoDevices = devices.filter(device => device.kind === 'videoinput');
console.log('Audio Input Devices:', audioDevices);
console.log('Video Input Devices:', videoDevices);
})
.catch(error => {
console.error('Media Devices Enumeration Error:', error);
});
Section 20: Bluetooth Device Information
// Bluetooth Device Information
const bluetoothSupported = 'bluetooth' in navigator;
console.log('Bluetooth Supported:', bluetoothSupported);
if (bluetoothSupported) {
navigator.bluetooth.getDevices()
.then(devices => {
console.log('Bluetooth Devices:', devices);
})
.catch(error => {
console.error('Bluetooth Devices Error:', error);
});
}