BatteryManager

  • Revision slug: Web/API/BatteryManager
  • Revision title: BatteryManager
  • Revision id: 409975
  • Created:
  • Creator: Jeremie
  • Is current revision? No
  • Comment

Revision Content

Summary

The BatteryManager interface provides ways to get information about the system's battery charge level.

The {{domxref("window.navigator.battery","navigator.battery")}} property return an instance of the BatteryManager interface.

Properties

{{domxref("BatteryManager.charging")}} {{ReadOnlyInline}}
A Boolean value indicating whether or not the battery is currently being charged.
{{domxref("BatteryManager.chargingTime")}} {{ReadOnlyInline}}
A number representing the remaining time in seconds until the battery is fully charged, or 0 if the battery is already fully charged.
{{domxref("BatteryManager.dischargingTime")}} {{ReadOnlyInline}}
A number representing the remaining time in seconds until the battery is completely discharged and the system will suspend.
{{domxref("BatteryManager.level")}} {{ReadOnlyInline}}
A number representing the system's battery charge level scaled to a value between 0.0 and 1.0.

Events handler

{{domxref("BatteryManager.onchargingchange")}}
A handler for the {{event("chargingchange")}} event; This event is sent when the battery charging state is updated.
{{domxref("BatteryManager.onchargingtimechange")}}
A handler for the {{event("chargingtimechange")}} event; This event is sent when the battery charging time is updated
{{domxref("BatteryManager.ondischargingtimechange")}}
A handler for the {{event("dischargingtimechange")}} event; This event is sent when the battery discharging time is updated.
{{domxref("BatteryManager.onlevelchange")}}
A handler for the {{event("levelchange")}} event; This event is sent when the battery level is updated.

Methods

Inherited from {{domxref("EventTarget")}}:

{{page("/en-US/docs/Web/API/EventTarget","Methods")}}

Specifications

Specification Status Comment
{{SpecName('Battery API')}} {{Spec2('Battery API')}} Initial specification.

Browser compatibility

{{ CompatibilityTable() }}

Feature Chrome Firefox (Gecko) Internet Explorer Opera Safari
Basic support {{ Unimplemented_inline_webkit("90538") }} {{CompatGeckoDesktop("10")}} {{ property_prefix("moz") }} [1]
{{CompatGeckoDesktop("16")}} (without prefix) [2]
{{ CompatNo() }} {{ CompatNo() }} {{ CompatNo() }}
Feature Android Chrome for Android Firefox Mobile (Gecko) IE Mobile Opera Mobile Safari Mobile
Basic support {{ CompatUnknown() }} {{ CompatNo() }} {{CompatGeckoMobile("10")}} {{ property_prefix("moz") }} [1]
{{CompatGeckoMobile("16")}} (without prefix) [2]
{{ CompatNo() }} {{ CompatNo() }} {{ CompatNo() }}

Gecko notes

[1] Disabled by default in Firefox 10.0, but can be enabled setting the preference dom.battery.enabled to true. Starting with Firefox 11.0, mozBattery is enabled by default.

[2] The Battery API is currently supported on Android, Windows, and Linux with UPower installed. Support for MacOS is available starting with Gecko 18.0 {{geckoRelease("18.0")}}.

See also

Revision Source

<h2>Summary</h2>
<p>The <code>BatteryManager</code> interface provides ways to get information about the system's battery charge level.</p>
<p>The {{domxref("window.navigator.battery","navigator.battery")}} property return an instance of the <code>BatteryManager</code> interface.</p>
<h2 id="Properties">Properties</h2>
<dl>
  <dt>
    {{domxref("BatteryManager.charging")}} {{ReadOnlyInline}}</dt>
  <dd>
    A Boolean value indicating whether or not the battery is currently being charged.</dd>
  <dt>
    {{domxref("BatteryManager.chargingTime")}} {{ReadOnlyInline}}</dt>
  <dd>
    A number representing the remaining time in seconds until the battery is fully charged, or 0 if the battery is already fully charged.</dd>
  <dt>
    {{domxref("BatteryManager.dischargingTime")}} {{ReadOnlyInline}}</dt>
  <dd>
    A number representing the remaining time in seconds until the battery is completely discharged and the system will suspend.</dd>
  <dt>
    {{domxref("BatteryManager.level")}} {{ReadOnlyInline}}</dt>
  <dd>
    A number representing the system's battery charge level scaled to a value between 0.0 and 1.0.</dd>
</dl>
<h3 id="Events">Events handler</h3>
<dl>
  <dt>
    {{domxref("BatteryManager.onchargingchange")}}</dt>
  <dd>
    A handler for the {{event("chargingchange")}} event; This event is sent when the battery charging state is updated.</dd>
  <dt>
    {{domxref("BatteryManager.onchargingtimechange")}}</dt>
  <dd>
    A handler for the {{event("chargingtimechange")}} event; This event is sent when the battery charging time is updated</dd>
  <dt>
    {{domxref("BatteryManager.ondischargingtimechange")}}</dt>
  <dd>
    A handler for the {{event("dischargingtimechange")}} event; This event is sent when the battery discharging time is updated.</dd>
  <dt>
    {{domxref("BatteryManager.onlevelchange")}}</dt>
  <dd>
    A handler for the {{event("levelchange")}} event; This event is sent when the battery level is updated.</dd>
</dl>
<h2>Methods</h2>
<p>Inherited from {{domxref("EventTarget")}}:</p>
<p>{{page("/en-US/docs/Web/API/EventTarget","Methods")}}</p>
<h2 id="Specifications">Specifications</h2>
<table class="standard-table">
  <thead>
    <tr>
      <th scope="col">Specification</th>
      <th scope="col">Status</th>
      <th scope="col">Comment</th>
    </tr>
  </thead>
  <tbody>
    <tr>
      <td>{{SpecName('Battery API')}}</td>
      <td>{{Spec2('Battery API')}}</td>
      <td>Initial specification.</td>
    </tr>
  </tbody>
</table>
<h2 id="Browser_compatibility">Browser compatibility</h2>
<p>{{ CompatibilityTable() }}</p>
<div id="compat-desktop">
  <table class="compat-table">
    <tbody>
      <tr>
        <th>Feature</th>
        <th>Chrome</th>
        <th>Firefox (Gecko)</th>
        <th>Internet Explorer</th>
        <th>Opera</th>
        <th>Safari</th>
      </tr>
      <tr>
        <td>Basic support</td>
        <td>{{ Unimplemented_inline_webkit("90538") }}</td>
        <td>{{CompatGeckoDesktop("10")}} {{ property_prefix("moz") }} [1]<br />
          {{CompatGeckoDesktop("16")}} (without prefix) [2]</td>
        <td>{{ CompatNo() }}</td>
        <td>{{ CompatNo() }}</td>
        <td>{{ CompatNo() }}</td>
      </tr>
    </tbody>
  </table>
</div>
<div id="compat-mobile">
  <table class="compat-table">
    <tbody>
      <tr>
        <th>Feature</th>
        <th>Android</th>
        <th>Chrome for Android</th>
        <th>Firefox Mobile (Gecko)</th>
        <th>IE Mobile</th>
        <th>Opera Mobile</th>
        <th>Safari Mobile</th>
      </tr>
      <tr>
        <td>Basic support</td>
        <td>{{ CompatUnknown() }}</td>
        <td>{{ CompatNo() }}</td>
        <td>{{CompatGeckoMobile("10")}} {{ property_prefix("moz") }} [1]<br />
          {{CompatGeckoMobile("16")}} (without prefix) [2]</td>
        <td>{{ CompatNo() }}</td>
        <td>{{ CompatNo() }}</td>
        <td>{{ CompatNo() }}</td>
      </tr>
    </tbody>
  </table>
</div>
<h3 id="Gecko_notes">Gecko notes</h3>
<p>[1] Disabled by default in Firefox 10.0, but can be enabled setting the preference <code>dom.battery.enabled</code> to <code>true</code>. Starting with Firefox 11.0, <code>mozBattery</code> is enabled by default.</p>
<p class="note">[2] The Battery API is currently supported on Android, Windows, and Linux with UPower installed. Support for MacOS is available starting with Gecko 18.0 {{geckoRelease("18.0")}}.</p>
<h2 id="See_also">See also</h2>
<ul>
  <li>{{ domxref("window.navigator.battery","navigator.battery") }}</li>
  <li>The <a href="/en-US/docs/WebAPI/Battery_Status" title="/en-US/docs/WebAPI/Battery_Status">Battery Status API</a></li>
</ul>
Revert to this revision