Skip to content

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
const userAgent = navigator.userAgent;
console.log('User-Agent:', userAgent);
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)
// User Agent Information (Simplified)
const userAgent = navigator.userAgent;
console.log(userAgent);
Section 4: Screen Information
// Screen Information
const screenWidth = window.screen.width;
const screenHeight = window.screen.height;
console.log('Screen Width:', screenWidth);
console.log('Screen Height:', screenHeight);
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
// Cookie Operations
const cookieValue = document.cookie;
document.cookie = "myCookie=myValue; expires=Fri, 31 Dec 9999 23:59:59 GMT; path=/";
document.cookie = "myCookie=; expires=Thu, 01 Jan 1970 00:00:00 GMT; path=/";
Section 7: Online/Offline Status
// Online/Offline Status
const isOnline = navigator.onLine;
console.log('Online Status:', isOnline);
Section 8: Timezone Information
// Timezone Information
const timezoneOffsetMinutes = new Date().getTimezoneOffset();
console.log('Timezone Offset (minutes):', timezoneOffsetMinutes);
Section 9: Language and Locale Information
// Language and Locale Information
const userLanguage = navigator.language;
console.log('User Language:', userLanguage);
const userLanguages = navigator.languages;
console.log('User Languages:', userLanguages);
Section 10: Mobile Device Detection
// Mobile Device Detection
const isMobile = /Mobi/.test(navigator.userAgent);
console.log('Is Mobile Device:', isMobile);
Section 11: Storage Availability
const localStorageAvailable = typeof localStorage !== 'undefined';
console.log('Local Storage Available:', localStorageAvailable);

const sessionStorageAvailable = typeof sessionStorage !== 'undefined';
console.log('Session Storage Available:', sessionStorageAvailable);
Section 12: Web Workers Support
const webWorkersSupported = typeof Worker !== 'undefined';
console.log('Web Workers Supported:', webWorkersSupported);
Section 13: Media Capabilities
navigator.mediaCapabilities
  .decodingInfo({ type: 'video/mp4; codecs="avc1.42E01E"' })
  .then(capabilities => {
    console.log('Media Capabilities:', capabilities);
  })
  .catch(error => {
    console.error('Media Capabilities Error:', error);
  });
Section 14: Battery Information
const batteryPromise = navigator.getBattery();
batteryPromise.then(battery => {
  console.log('Battery Level:', battery.level * 100 + '%');
  console.log('Charging:', battery.charging);
});
Section 15: Device Memory Information
// Device Memory Information
const deviceMemory = navigator.deviceMemory;
console.log('Device Memory (GB):', deviceMemory);
Section 16: Hardware Concurrency Information
// Hardware Concurrency Information
const hardwareConcurrency = navigator.hardwareConcurrency;
console.log('Hardware Concurrency:', hardwareConcurrency);
Section 17: Gamepad Information
// Gamepad Information
window.addEventListener("gamepadconnected", function(event) {
  const gamepad = event.gamepad;
  console.log('Gamepad ID:', gamepad.id);
});
Section 18: VR/AR Device Information
// VR/AR Device Information
const xrSupported = 'xr' in navigator;
console.log('XR (VR/AR) Supported:', xrSupported);

if (xrSupported) {
  navigator.xr.getDevices().then(devices => {
    console.log('XR Devices:', devices);
  });
}
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);
    });
}