browser-battery
v2.0.0
Published
Get and watch battery information in a browser
Downloads
445
Maintainers
Readme
browser-battery
Get and watch battery information in a browser
Currently working in Chrome, Firefox and Opera.
Install
$ npm install --save browser-battery
Usage
const browserBattery = require('browser-battery');
browserBattery().then(battery => {
console.log(battery);
/*
{
charging: false
chargingTime: Infinity
dischargingTime: 11160
level: 0.6
onchargingchange: null
onchargingtimechange: null
ondischargingtimechange: null
onlevelchange: null
}
*/
});
// Use the event listeners
browserBattery().then(battery => {
battery.onlevelchange = function () {
console.log(battery.level);
//=> 0.89
};
});
Related
- battery-level - Get current battery level (OS X, Linux and Windows)
License
MIT © Andreas Gillström