Example

by understore

HTML

<!-- Learn about this code on MDN: https://developer.mozilla.org/en-US/docs/Web/API/BatteryManager/charging -->

<div id="charging">(charging state unknown)</div>

JavaScript

navigator
		.getBattery()
    .then(function(battery) {
        console.log(22);
		})
		.then(function(){console.log(11);});