3 ms·
Basically: navigator.getBattery().then(battery => console.log(`Battery level: ${battery.level \* 100}%`)) C.f.: https://developer.mozilla.org/en-US/docs/Web
by _ache_ 3y ago
Basically:
navigator.getBattery().then(battery => console.log(`Battery level: ${battery.level \* 100}%`))
C.f.: https://developer.mozilla.org/en-US/docs/Web/API/Battery_Status_API https://developer.mozilla.org/en-US/docs/Web/API/Battery_Sta...
- rvnx 3y agoWorks as expected, the same way there are APIs for the device orientation, etc. Eventually these get placed behind permissions if they become too much widely abused. As explained in the standards: "This can be used to adjust your app's resource usage to reduce battery drain when the battery is low, or to save changes before the battery runs out in order to prevent data loss".
- cantSpellSober 3y agoI believe this is behind permissions, the Permissions-Policy directive "battery"