Example

by dshilkret

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(ws) {
        var windowState = ws;
        document.querySelector('#charging').textContent = charging ;
		})
		.then(function(){alert("Charging is true");});