Battery Status

The Battery Status API allows web applications to get the information about the device's power source, battery charge level, expected time of charging or discharging. It also exposes events whenever any of the information available changes. The API allows the applications to turn on/off its energy inefficient operations according to the power levels.

API glimpse

navigator.getBattery()
Returns a Promise resolved with the object containing battery information.
battery.charging
Returns true if the device is currently being charged.
battery.chargingTime
Returns the number of seconds remaining until the battery is fully charged.
battery.dischargingTime
Returns the number of seconds remaining until the battery is fully discharged.
battery.level
Returns the battery charging level as the number in 0 to 1 range.
battery.addEventListener('chargingchange', listener)
An event fired when battery.charging value has changed.
battery.addEventListener('chargingtimechange', listener)
An event fired when battery.chargingTime value has changed.
battery.addEventListener('dischargingtimechange', listener)
An event fired when battery.dischargingTime value has changed.
battery.addEventListener('levelchange', listener)
An event fired when battery.level value has changed.

Resources