coderef

Battery statusLimited availability

The navigator.getBattery() API obtains information about the device's battery, including charge level and status. Also known as the Battery API.

Not yet supported in all major browsers — check the table and provide a fallback.

Browser support

DesktopChrome
1–37Not supported
38+Supportedsince Oct 7, 2014
Current: 155
Edge
12–18Not supported
79+Supportedsince Jan 15, 2020
Current: 154
Firefox
✕Not supportedup to 157
Current: 157
Safari
✕Not supportedup to 27
Current: 27
MobileChrome Android
18–37Not supported
38+Supportedsince Oct 8, 2014
Current: 155
Firefox Android
✕Not supportedup to 157
Current: 157
Safari iOS
✕Not supportedup to 27
Current: 27

How to use

Not supported in Firefox, Safari, Firefox Android, Safari iOS. Use feature detection below and provide a fallback (or a polyfill) for those browsers.

Example

Full syntax and examples are on MDN: BatteryManager.

Feature detection

JS · check before using
if ("BatteryManager" in globalThis) {
  // BatteryManager is available
} else {
  // load a polyfill or use a fallback
}

Sub-features

Support for each part of the feature (12). The overall table above shows when the whole feature works.

Sub-featureChromeEdgeFirefoxSafariChrome AndroidFirefox AndroidSafari iOS
BatteryManager3879✕✕38✕✕
BatteryManager.charging3879✕✕38✕✕
BatteryManager.chargingTime3879✕✕42✕✕
BatteryManager.chargingchange_event3879✕✕38✕✕
BatteryManager.chargingtimechange_event3879✕✕38✕✕
BatteryManager.dischargingTime3879✕✕42✕✕
BatteryManager.dischargingtimechange_event3879✕✕38✕✕
BatteryManager.level3879✕✕38✕✕
BatteryManager.levelchange_event3879✕✕38✕✕
BatteryManager.secure_context_required103103✕✕103✕✕
Navigator.getBattery3879✕✕38✕✕
Navigator.getBattery.secure_context_required103103✕✕103✕✕