Battery Status
navigator.getBattery() returns a BatteryManager with level, charging state, and time estimates, plus four events that fire when any of those change. Chrome and Android only -- not iOS, and Firefox removed it over fingerprinting concerns.
There is a real app called Die With Me. You can only open it when your battery is below 5%. The premise is chatting with strangers while you both run out of power together.
The Battery Status API is what makes that possible.
const battery = await navigator.getBattery()
console.log(battery.level) // 0.05 = 5%
console.log(battery.charging) // false = on batterynavigator.getBattery() returns a Promise that resolves to a BatteryManager object. The properties on that object are your window into the device's power state.
BatteryManager Properties
battery.level // 0.0 to 1.0 -- multiply by 100 for percentage
battery.charging // true if power is connected
battery.chargingTime // seconds until full (Infinity if not charging)
battery.dischargingTime // seconds until empty (Infinity if charging)level is a float between 0 and 1. 0.27 is 27%. The browser updates it roughly at each percentage point change.
chargingTime and dischargingTime are estimates the OS provides. They can be Infinity when no estimate is available -- when a device is first plugged in, for example, or when it has just been unplugged and the OS has not yet computed the projection.
Events
battery.addEventListener('chargingchange', () => {
console.log('Power cable:', battery.charging ? 'connected' : 'disconnected')
})
battery.addEventListener('levelchange', () => {
console.log('Battery level:', Math.round(battery.level * 100), '%')
if (battery.level < 0.1 && !battery.charging) {
showLowBatteryWarning()
}
})
battery.addEventListener('chargingtimechange', () => {
console.log('Time to full:', battery.chargingTime, 'seconds')
})
battery.addEventListener('dischargingtimechange', () => {
console.log('Time remaining:', battery.dischargingTime, 'seconds')
})chargingchange fires when the charging cable is plugged or unplugged. levelchange fires when the level property changes. The timing and granularity are determined by the OS -- typically this is per percentage point.
ExpandBattery Status API: properties on BatteryManager and the four events that fire on state change
Practical Uses
Low battery warning. When battery.level drops below 0.1 and battery.charging is false, surface a message. A Bluetooth light app might warn: "Your Bluetooth device and browser session may disconnect when the device powers off."
Reduce resource usage on low power. Stop background polling, pause non-essential animations, lower WebSocket ping frequency. The OS may already be throttling, but being proactive is good citizenship.
Charging state change. When chargingchange fires and battery.charging becomes true, resume operations you paused. Start a longer background sync. Update the UI to show the user they are safe to continue.
Privacy and Support
The Battery Status API has a complicated history. Firefox implemented it, then removed it. The reason: battery.level, chargingTime, and dischargingTime together form a reasonably stable fingerprint that can identify a specific device across sessions and origins, even in private browsing mode.
Current support: Chrome, Edge, Chrome on Android, Samsung Internet, and Opera Android. Roughly 75% of browser traffic globally -- but not iOS, and not Firefox.
On iOS, there is no alternative. Apple's APIs that expose battery state are not accessible from the Safari web layer. If you need iOS battery monitoring, a PWA published through the App Store can use native Swift to read UIDevice.current.batteryLevel and expose it to a JavaScript bridge -- but that path requires going through the App Store.
if ('getBattery' in navigator) {
const battery = await navigator.getBattery()
}Battery state tells you power is low. The Idle Detection API tells you whether the user is still there at all -- a question that turns out to require OS-level signals rather than just tab focus.
The Essentials
navigator.getBattery()returns a Promise resolving to aBatteryManagerobject.- Properties:
level(0–1),charging(boolean),chargingTime(seconds to full),dischargingTime(seconds to empty). Both time estimates can beInfinitywhen the OS has no projection yet. - Four events:
chargingchange,levelchange,chargingtimechange,dischargingtimechange. All fire when their corresponding property changes. - Chrome and Android browsers only. Firefox removed it over fingerprinting concerns. iOS Safari does not support it.
- No iOS alternative exists without a native Swift bridge through the App Store.
Further Reading and Watching
- How to Use the Navigator Battery API in JavaScript (YouTube) -- covers
getBattery(), all four properties, and event handling for charging and level changes - Battery Status API -- MDN -- full reference with the privacy note about fingerprinting, browser support table, and BatteryManager interface details
Keep reading