This feature is not Baseline because it does not work in some of the most widely-used browsers.
Secure context: This feature is available only in secure contexts (HTTPS), in some or all supporting browsers.
The getBattery() method provides information about the system's battery. It returns a battery promise, which resolves with a BatteryManager object providing some properties to get the battery status also some events you can handle to monitor the battery status. This implements the Battery Status API; see that documentation for additional details, a guide to using the API, and sample code.
Since Chrome 103, the Navigator.getBattery() method of Battery Status API only expose to secure context.
Note: Access to this feature may be controlled by the Permissions-Policy directive battery.
getBattery()
None.
A Promise that fulfills with a BatteryManager object which you can use to get information about the battery's state.
NotAllowedError DOMException
Use of this feature was blocked by a Permissions Policy.
SecurityError DOMException
The User Agent does not expose battery information to insecure contexts and this method was called from an insecure context.
This example fetches the current charging state of the battery and establishes a handler for the chargingchange event, so that the charging state is recorded whenever it changes.
let batteryIsCharging = false;
navigator.getBattery().then((battery) => {
batteryIsCharging = battery.charging;
battery.addEventListener("chargingchange", () => {
batteryIsCharging = battery.charging;
});
});
For more examples and details, see Battery Status API.
| Specification |
|---|
| Battery Status API> # dom-navigator-getbattery> |
| Desktop | Mobile | |||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|
| Chrome | Edge | Firefox | Opera | Safari | Chrome Android | Firefox for Android | Opera Android | Safari on IOS | Samsung Internet | WebView Android | WebView on iOS | |
getBattery |
38 | 79 | 43–52 | 25 | No | 38 | 43–52 | 25 | No | 3.0 | 38 | No |
secure_context_required |
103 | 103 | No | No | No | 103 | No | 71 | No | 20.0 | 103 | No |
Permissions-Policy battery directive
© 2005–2025 MDN contributors.
Licensed under the Creative Commons Attribution-ShareAlike License v2.5 or later.
https://developer.mozilla.org/en-US/docs/Web/API/Navigator/getBattery