Skip to content

Instantly share code, notes, and snippets.

@JustinDFuller

JustinDFuller/battery.js

Last active Jan 9, 2017
Embed
What would you like to do?
Battery status API
if ('getBattery' in navigator) {
navigator.getBattery().then(battery => {
console.log('Initial', battery);
battery.onchargingchange = onchange;
battery.onchargingtimechange = onchange;
battery.ondischargingtimechange = onchange;
battery.onlevelchange = onchange;
function onchange (event) {
console.log('On change, type: %s', event.type, battery);
}
});
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.