Yes, you heard me right, the Battery API! As the web expands, so does the number of devices we expect to use our programs. This API can be particularly useful for protecting our mobile users and their precious battery life! So before we look at the API lets think of some reasons why we might need such a thing: Decreasing processing and requests when the battery is low. Provide users with warnings. Especially useful if your users are working with time-sensitive data or actions, or if you know your app is a power-drainer. Serve a simpler, low power version of the site. So let’s take a look at how you might use it. A few things to note in the above example: is not available in all browsers. Make sure you perform a check before attempting to use it! getBattery The return value of is a which resolves with the object. getBattery Promise BatteryManager When the function is called, you must re-inspect the original object that was provided by the promise. It will be modified and contain the new battery information. onchange BatteryManager When the function is called it receives one argument, , which helpfully contains that tells us which battery event happened. This allows you to reuse a single event handler! onchange event event.type Using The Data Now that we see how to the data, let’s take a look at how we can it! get use In this example we will watch for the battery to get low, and show an alert when it’s below a certain level. The battery properties we are inspecting: is the amount of time until the battery is empty, in seconds. Its value will be if the device is plugged in to a power source. dischargeTime infinity is a percentage. So is 20%. level 0.2 You can customize these to fit your needs. In a highly time-sensitive environment you may want to let them know earlier than 20% or 20 minutes. A final note: Most devices will warn users when the battery is low, so you likely won’t need to add the example warning message to your application. Instead, you could limit your processes and display a message that processing is limited until the battery has been charged. Remember, this API is just another resource that allows you to solve problems for your users. Feel free to check out some of my past posts: , . Console API Video API Hi, I’m Justin Fuller. I’m so glad you read my post! I need to let you know that everything I’ve written here is my own opinion and is not intended to represent my employer in way. All code samples are my own, and are completely unrelated to Bank Of America’s code. any I’d also love to hear from you, please feel free to connect with me on , , or . Thanks again for reading! LinkedIn Github Medium is how hackers start their afternoons. We’re a part of the family. We are now and happy to opportunities. Hacker Noon @AMI accepting submissions discuss advertising &sponsorship To learn more, , , or simply, read our about page like/message us on Facebook tweet/DM @HackerNoon. If you enjoyed this story, we recommend reading our and . Until next time, don’t take the realities of the world for granted! latest tech stories trending tech stories