(Ab)Using the HTML5 Battery Status API for Advertising

The Device and Sensor Working Group is tasked with creating client-side APIs that interact with device hardware, sensors, services and applications such as the camera, microphone, proximity sensors, native address books, calendars and the Battery Status API.

The Battery Status API provides information about the system's battery charge level and lets you be notified by events that are sent when the battery level or charging status change. 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.

At the time of writing, the Battery Status API is supported by Firefox, Chrome and Opera.
Battery Status API Browser Support

The API will return something like this

BatteryManager: {  
    charging:false,
    chargingTime:Infinity,
    dischargingTime:8374,
    level:0.77
}

Originally, this API was designed to be used for developers to save battery power. For example, according to Battery Level, developers could:

  • Lower Geolocation accuracy
  • Playback videos in lower quality
  • Reduce complex CSS animations
  • Reduce intervals for background tasks
  • Disable vibration
  • Decrease network activity
  • Change page color scheme to reduce battery drain

However, since this API doesn't require the browser to request permission from the user it can also be abused. Recently, privacy researchers proved that this API can be used to track users (at least those using Firefox on Linux mostly).

The Effect of a Dying Battery on Users

Uber's head of economic research, Keith Chen (@MKeithChen), recently told NPR's Shankar Vedantam on an episode of The Hidden Brain podcast (This Is Your Brain On Uber) that people are willing to accept up to 9.9 times surge pricing if their phones are about to die.

"One of the strongest predictors of whether or not you are going to be sensitive to surge - in other words, whether or not you are going to kind of say, oh, 2.2, 2.3, I’ll give it a 10 to 15 minutes to see if surge goes away - is how much battery you have left on your cell phone" - Keith Chen

Proof of Concept

(Un)fortunately, the Battery Status API provides developers all the tools they need to be able to use this kind of information on their users.

With just a few lines of Javascript, you can get this information: