Walter
Walter

Reputation: 25

How to get battery percentage from the browser using Javascript?

How to get the user's battery percentage on a web application using JavaScript.

Since it's a web application, it'll run on a browser. The percentage will be displayed on the webpage.

Upvotes: 0

Views: 5109

Answers (1)

Muljayan
Muljayan

Reputation: 3886

You can use the Battery status API. It only works on some browsers like chrome.

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

You can find more information here.

The link provided is a candidate recommendation and is not a finalized api.

Upvotes: 9

Related Questions