What does the Battery API report on a desktop computer?

I was discussing with Chris Mills how to build an example for Web APIs that was clear enough yet showed some sort of API usage in action. He had chosen the Battery API which is, effectively, simple enough. But I had a question: what does this API report when you run it in a device without battery?

Nothing better than building an example, so that’s what I did.

On a laptop

It reports the battery level and discharging / charging, plus the time left, if not at the maximum level already.

battery api on a laptop

On a desktop

It reports battery level at 100%, charging, and 0 seconds to charge.

battery api on a desktop

Mystery solved!

A final note/remark: while going through the API docs I found it so very synchronous and unpromise-y! If this API was written nowadays it would probably be done with Promises or some sort of asynchronicity by default. I wonder if that will be retrofitted.

2 thoughts on “What does the Battery API report on a desktop computer?

  1. Thanks for this, it seems like a very worthwhile thing to check. We ought to start doing things with the battery API.

    One problem: your demo link 404s, I think you’re missing an ‘http’!

  2. Thanks! I’m sad it’s not implemented YET in Chrome/Chrome OS, but they’re on it!

    I’ve corrected the link. I hadn’t had a coffee this morning. haha!

Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>