Battery Status API

非推奨
この機能はウェブ標準から削除されました。まだ対応しているプラウザーがあるかもしれませんが、ゆくゆくはなくなるものです。使用を避け、できれば既存のコードを更新してください。このページの下部にあるブラウザーの対応を見て判断してください。この機能は突然動作しなくなる可能性があることに注意してください。

Battery Status API は、 Battery API と呼ばれることの方が多いのですが、システムのバッテリー充電レベルに関する情報の提供、およびバッテリーレベルや充電状態が変化したときに発生するイベントによる通知を可能にします。これは、バッテリーが消耗したときにバッテリー消費を減らすためアプリのリソース使用状況を調整したり、データを失わないためにバッテリーが切れる前に変更点を保存したりするために使用できます。

Battery Status API は window.navigator を、 battery promise を返す navigator.getBattery() メソッドで拡張します。 Promise は、バッテリーの状態監視を制御できる新たなイベントも提供する、BatteryManager オブジェクトで解決します。

以下の例では、充電状況 (電源に接続して充電中であるか) の変化およびバッテリーレベルの変化およびタイミングを監視します。これは、 chargingchange, levelchange, chargingtimechange, dischargingtimechange の各イベントをそれぞれ待ち受けすることによって実現します。

navigator.getBattery().then(function(battery) {
  function updateAllBatteryInfo(){
    updateChargeInfo();
    updateLevelInfo();
    updateChargingInfo();
    updateDischargingInfo();
  }
  updateAllBatteryInfo();

  battery.addEventListener('chargingchange', function(){
    updateChargeInfo();
  });
  function updateChargeInfo(){
    console.log("Battery charging? "
                + (battery.charging ? "Yes" : "No"));
  }

  battery.addEventListener('levelchange', function(){
    updateLevelInfo();
  });
  function updateLevelInfo(){
    console.log("Battery level: "
                + battery.level * 100 + "%");
  }

  battery.addEventListener('chargingtimechange', function(){
    updateChargingInfo();
  });
  function updateChargingInfo(){
    console.log("Battery charging time: "
                 + battery.chargingTime + " seconds");
  }

  battery.addEventListener('dischargingtimechange', function(){
    updateDischargingInfo();
  });
  function updateDischargingInfo(){
    console.log("Battery discharging time: "
                 + battery.dischargingTime + " seconds");
  }

});

仕様書に記載されているサンプルもご覧ください。

仕様書

仕様書 状態 備考
Battery Status API 勧告候補 初回定義

ブラウザーの互換性

Update compatibility data on GitHub
デスクトップモバイル
ChromeEdgeFirefoxInternet ExplorerOperaSafariAndroid webviewAndroid 版 ChromeAndroid 版 FirefoxAndroid 版 OperaiOSのSafariSamsung Internet
BatteryManager
非推奨
Chrome 完全対応 38Edge 完全対応 79Firefox 未対応 16 — 52
未対応 16 — 52
未対応 10 — 16
接頭辞付き
接頭辞付き moz のベンダー接頭辞が必要
完全対応 52
補足 無効
補足 Disabled by default in Firefox 10, but can be enabled setting the preference dom.battery.enabled to true. Starting with Firefox 11, mozBattery is enabled by default. The Battery API is currently supported on Android, Windows, and Linux with UPower installed. Support for MacOS is available starting with Firefox 18. Firefox also provides support for the deprecated navigator.battery.
無効 From version 52: this feature is behind the dom.battery.enabled preference. To change preferences in Firefox, visit about:config.
完全対応 72
補足
補足 From this version onwards, BatteryManager is only available in chrome/privileged code.
IE 未対応 なしOpera 完全対応 25Safari 未対応 なしWebView Android 完全対応 40Chrome Android 完全対応 38
補足
完全対応 38
補足
補足 Values for BatteryManager.chargingTime and BatteryManager.dischargingTime are always equal to Infinity.
Firefox Android 未対応 10 — 16
接頭辞付き
未対応 10 — 16
接頭辞付き
接頭辞付き moz のベンダー接頭辞が必要
未対応 16 — 52
補足 無効
補足 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. The Battery API is currently supported on Android, Windows, and Linux with UPower installed. Support for MacOS is available starting with Gecko 18.0 (Firefox 18.0 / Thunderbird 18.0 / SeaMonkey 2.15). Firefox also provides support for the deprecated navigator.battery.
無効 From version 16 until version 52 (exclusive): this feature is behind the dom.battery.enabled preference. To change preferences in Firefox, visit about:config.
Opera Android 完全対応 25Safari iOS 未対応 ? — ?Samsung Internet Android 完全対応 3.0
補足
完全対応 3.0
補足
補足 Values for BatteryManager.chargingTime and BatteryManager.dischargingTime are always equal to Infinity.
charging
非推奨
Chrome 完全対応 38Edge 完全対応 79Firefox 未対応 16 — 52
未対応 16 — 52
未対応 10 — 16
接頭辞付き
接頭辞付き moz のベンダー接頭辞が必要
完全対応 52
補足 無効
補足 Disabled by default in Firefox 10, but can be enabled setting the preference dom.battery.enabled to true. Starting with Firefox 11, mozBattery is enabled by default. The Battery API is currently supported on Android, Windows, and Linux with UPower installed. Support for MacOS is available starting with Firefox 18. Firefox also provides support for the deprecated navigator.battery.
無効 From version 52: this feature is behind the dom.battery.enabled preference. To change preferences in Firefox, visit about:config.
完全対応 72
補足
補足 From this version onwards, BatteryManager is only available in chrome/privileged code.
IE 未対応 なしOpera 完全対応 25Safari 未対応 なしWebView Android 完全対応 40Chrome Android 完全対応 38
補足
完全対応 38
補足
補足 Values for BatteryManager.chargingTime and BatteryManager.dischargingTime are always equal to Infinity.
Firefox Android 未対応 10 — 16
接頭辞付き
未対応 10 — 16
接頭辞付き
接頭辞付き moz のベンダー接頭辞が必要
未対応 16 — 52
補足 無効
補足 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. The Battery API is currently supported on Android, Windows, and Linux with UPower installed. Support for MacOS is available starting with Gecko 18.0 (Firefox 18.0 / Thunderbird 18.0 / SeaMonkey 2.15). Firefox also provides support for the deprecated navigator.battery.
無効 From version 16 until version 52 (exclusive): this feature is behind the dom.battery.enabled preference. To change preferences in Firefox, visit about:config.
Opera Android 完全対応 25Safari iOS 未対応 ? — ?Samsung Internet Android 完全対応 3.0
補足
完全対応 3.0
補足
補足 Values for BatteryManager.chargingTime and BatteryManager.dischargingTime are always equal to Infinity.
chargingTime
非推奨
Chrome 完全対応 38Edge 完全対応 79Firefox 未対応 16 — 52
未対応 16 — 52
未対応 10 — 16
接頭辞付き
接頭辞付き moz のベンダー接頭辞が必要
完全対応 52
補足 無効
補足 Disabled by default in Firefox 10, but can be enabled setting the preference dom.battery.enabled to true. Starting with Firefox 11, mozBattery is enabled by default. The Battery API is currently supported on Android, Windows, and Linux with UPower installed. Support for MacOS is available starting with Firefox 18. Firefox also provides support for the deprecated navigator.battery.
無効 From version 52: this feature is behind the dom.battery.enabled preference. To change preferences in Firefox, visit about:config.
完全対応 72
補足
補足 From this version onwards, BatteryManager is only available in chrome/privileged code.
IE 未対応 なしOpera 完全対応 25Safari 未対応 なしWebView Android 完全対応 40Chrome Android 完全対応 38
補足
完全対応 38
補足
補足 Values for BatteryManager.chargingTime and BatteryManager.dischargingTime are always equal to Infinity.
Firefox Android 未対応 10 — 16
接頭辞付き
未対応 10 — 16
接頭辞付き
接頭辞付き moz のベンダー接頭辞が必要
未対応 16 — 52
補足 無効
補足 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. The Battery API is currently supported on Android, Windows, and Linux with UPower installed. Support for MacOS is available starting with Gecko 18.0 (Firefox 18.0 / Thunderbird 18.0 / SeaMonkey 2.15). Firefox also provides support for the deprecated navigator.battery.
無効 From version 16 until version 52 (exclusive): this feature is behind the dom.battery.enabled preference. To change preferences in Firefox, visit about:config.
Opera Android 完全対応 25Safari iOS 未対応 ? — ?Samsung Internet Android 完全対応 3.0
補足
完全対応 3.0
補足
補足 Values for BatteryManager.chargingTime and BatteryManager.dischargingTime are always equal to Infinity.
dischargingTime
非推奨
Chrome 完全対応 38Edge 完全対応 79Firefox 未対応 16 — 52
未対応 16 — 52
未対応 10 — 16
接頭辞付き
接頭辞付き moz のベンダー接頭辞が必要
完全対応 52
補足 無効
補足 Disabled by default in Firefox 10, but can be enabled setting the preference dom.battery.enabled to true. Starting with Firefox 11, mozBattery is enabled by default. The Battery API is currently supported on Android, Windows, and Linux with UPower installed. Support for MacOS is available starting with Firefox 18. Firefox also provides support for the deprecated navigator.battery.
無効 From version 52: this feature is behind the dom.battery.enabled preference. To change preferences in Firefox, visit about:config.
完全対応 72
補足
補足 From this version onwards, BatteryManager is only available in chrome/privileged code.
IE 未対応 なしOpera 完全対応 25Safari 未対応 なしWebView Android 完全対応 40Chrome Android 完全対応 38
補足
完全対応 38
補足
補足 Values for BatteryManager.chargingTime and BatteryManager.dischargingTime are always equal to Infinity.
Firefox Android 未対応 10 — 16
接頭辞付き
未対応 10 — 16
接頭辞付き
接頭辞付き moz のベンダー接頭辞が必要
未対応 16 — 52
補足 無効
補足 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. The Battery API is currently supported on Android, Windows, and Linux with UPower installed. Support for MacOS is available starting with Gecko 18.0 (Firefox 18.0 / Thunderbird 18.0 / SeaMonkey 2.15). Firefox also provides support for the deprecated navigator.battery.
無効 From version 16 until version 52 (exclusive): this feature is behind the dom.battery.enabled preference. To change preferences in Firefox, visit about:config.
Opera Android 完全対応 25Safari iOS 未対応 ? — ?Samsung Internet Android 完全対応 3.0
補足
完全対応 3.0
補足
補足 Values for BatteryManager.chargingTime and BatteryManager.dischargingTime are always equal to Infinity.
level
非推奨
Chrome 完全対応 38Edge 完全対応 79Firefox 未対応 16 — 52
未対応 16 — 52
未対応 10 — 16
接頭辞付き
接頭辞付き moz のベンダー接頭辞が必要
完全対応 52
補足 無効
補足 Disabled by default in Firefox 10, but can be enabled setting the preference dom.battery.enabled to true. Starting with Firefox 11, mozBattery is enabled by default. The Battery API is currently supported on Android, Windows, and Linux with UPower installed. Support for MacOS is available starting with Firefox 18. Firefox also provides support for the deprecated navigator.battery.
無効 From version 52: this feature is behind the dom.battery.enabled preference. To change preferences in Firefox, visit about:config.
完全対応 72
補足
補足 From this version onwards, BatteryManager is only available in chrome/privileged code.
IE 未対応 なしOpera 完全対応 25Safari 未対応 なしWebView Android 完全対応 40Chrome Android 完全対応 38
補足
完全対応 38
補足
補足 Values for BatteryManager.chargingTime and BatteryManager.dischargingTime are always equal to Infinity.
Firefox Android 未対応 10 — 16
接頭辞付き
未対応 10 — 16
接頭辞付き
接頭辞付き moz のベンダー接頭辞が必要
未対応 16 — 52
補足 無効
補足 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. The Battery API is currently supported on Android, Windows, and Linux with UPower installed. Support for MacOS is available starting with Gecko 18.0 (Firefox 18.0 / Thunderbird 18.0 / SeaMonkey 2.15). Firefox also provides support for the deprecated navigator.battery.
無効 From version 16 until version 52 (exclusive): this feature is behind the dom.battery.enabled preference. To change preferences in Firefox, visit about:config.
Opera Android 完全対応 25Safari iOS 未対応 ? — ?Samsung Internet Android 完全対応 3.0
補足
完全対応 3.0
補足
補足 Values for BatteryManager.chargingTime and BatteryManager.dischargingTime are always equal to Infinity.
onchargingchange
非推奨
Chrome 完全対応 38Edge 完全対応 79Firefox 未対応 16 — 52
未対応 16 — 52
未対応 10 — 16
接頭辞付き
接頭辞付き moz のベンダー接頭辞が必要
完全対応 52
補足 無効
補足 Disabled by default in Firefox 10, but can be enabled setting the preference dom.battery.enabled to true. Starting with Firefox 11, mozBattery is enabled by default. The Battery API is currently supported on Android, Windows, and Linux with UPower installed. Support for MacOS is available starting with Firefox 18. Firefox also provides support for the deprecated navigator.battery.
無効 From version 52: this feature is behind the dom.battery.enabled preference. To change preferences in Firefox, visit about:config.
完全対応 72
補足
補足 From this version onwards, BatteryManager is only available in chrome/privileged code.
IE 未対応 なしOpera 完全対応 25Safari 未対応 なしWebView Android 完全対応 40Chrome Android 完全対応 38
補足
完全対応 38
補足
補足 Values for BatteryManager.chargingTime and BatteryManager.dischargingTime are always equal to Infinity.
Firefox Android 未対応 10 — 16
接頭辞付き
未対応 10 — 16
接頭辞付き
接頭辞付き moz のベンダー接頭辞が必要
未対応 16 — 52
補足 無効
補足 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. The Battery API is currently supported on Android, Windows, and Linux with UPower installed. Support for MacOS is available starting with Gecko 18.0 (Firefox 18.0 / Thunderbird 18.0 / SeaMonkey 2.15). Firefox also provides support for the deprecated navigator.battery.
無効 From version 16 until version 52 (exclusive): this feature is behind the dom.battery.enabled preference. To change preferences in Firefox, visit about:config.
Opera Android 完全対応 25Safari iOS 未対応 ? — ?Samsung Internet Android 完全対応 3.0
補足
完全対応 3.0
補足
補足 Values for BatteryManager.chargingTime and BatteryManager.dischargingTime are always equal to Infinity.
onchargingtimechange
非推奨
Chrome 完全対応 38Edge 完全対応 79Firefox 未対応 16 — 52
未対応 16 — 52
未対応 10 — 16
接頭辞付き
接頭辞付き moz のベンダー接頭辞が必要
完全対応 52
補足 無効
補足 Disabled by default in Firefox 10, but can be enabled setting the preference dom.battery.enabled to true. Starting with Firefox 11, mozBattery is enabled by default. The Battery API is currently supported on Android, Windows, and Linux with UPower installed. Support for MacOS is available starting with Firefox 18. Firefox also provides support for the deprecated navigator.battery.
無効 From version 52: this feature is behind the dom.battery.enabled preference. To change preferences in Firefox, visit about:config.
完全対応 72
補足
補足 From this version onwards, BatteryManager is only available in chrome/privileged code.
IE 未対応 なしOpera 完全対応 25Safari 未対応 なしWebView Android 完全対応 40Chrome Android 完全対応 38
補足
完全対応 38
補足
補足 Values for BatteryManager.chargingTime and BatteryManager.dischargingTime are always equal to Infinity.
Firefox Android 未対応 10 — 16
接頭辞付き
未対応 10 — 16
接頭辞付き
接頭辞付き moz のベンダー接頭辞が必要
未対応 16 — 52
補足 無効
補足 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. The Battery API is currently supported on Android, Windows, and Linux with UPower installed. Support for MacOS is available starting with Gecko 18.0 (Firefox 18.0 / Thunderbird 18.0 / SeaMonkey 2.15). Firefox also provides support for the deprecated navigator.battery.
無効 From version 16 until version 52 (exclusive): this feature is behind the dom.battery.enabled preference. To change preferences in Firefox, visit about:config.
Opera Android 完全対応 25Safari iOS 未対応 ? — ?Samsung Internet Android 完全対応 3.0
補足
完全対応 3.0
補足
補足 Values for BatteryManager.chargingTime and BatteryManager.dischargingTime are always equal to Infinity.
ondischargingtimechange
非推奨
Chrome 完全対応 38Edge 完全対応 79Firefox 未対応 16 — 52
未対応 16 — 52
未対応 10 — 16
接頭辞付き
接頭辞付き moz のベンダー接頭辞が必要
完全対応 52
補足 無効
補足 Disabled by default in Firefox 10, but can be enabled setting the preference dom.battery.enabled to true. Starting with Firefox 11, mozBattery is enabled by default. The Battery API is currently supported on Android, Windows, and Linux with UPower installed. Support for MacOS is available starting with Firefox 18. Firefox also provides support for the deprecated navigator.battery.
無効 From version 52: this feature is behind the dom.battery.enabled preference. To change preferences in Firefox, visit about:config.
完全対応 72
補足
補足 From this version onwards, BatteryManager is only available in chrome/privileged code.
IE 未対応 なしOpera 完全対応 25Safari 未対応 なしWebView Android 完全対応 40Chrome Android 完全対応 38
補足
完全対応 38
補足
補足 Values for BatteryManager.chargingTime and BatteryManager.dischargingTime are always equal to Infinity.
Firefox Android 未対応 10 — 16
接頭辞付き
未対応 10 — 16
接頭辞付き
接頭辞付き moz のベンダー接頭辞が必要
未対応 16 — 52
補足 無効
補足 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. The Battery API is currently supported on Android, Windows, and Linux with UPower installed. Support for MacOS is available starting with Gecko 18.0 (Firefox 18.0 / Thunderbird 18.0 / SeaMonkey 2.15). Firefox also provides support for the deprecated navigator.battery.
無効 From version 16 until version 52 (exclusive): this feature is behind the dom.battery.enabled preference. To change preferences in Firefox, visit about:config.
Opera Android 完全対応 25Safari iOS 未対応 ? — ?Samsung Internet Android 完全対応 3.0
補足
完全対応 3.0
補足
補足 Values for BatteryManager.chargingTime and BatteryManager.dischargingTime are always equal to Infinity.
onlevelchange
非推奨
Chrome 完全対応 38Edge 完全対応 79Firefox 未対応 16 — 52
未対応 16 — 52
未対応 10 — 16
接頭辞付き
接頭辞付き moz のベンダー接頭辞が必要
完全対応 52
補足 無効
補足 Disabled by default in Firefox 10, but can be enabled setting the preference dom.battery.enabled to true. Starting with Firefox 11, mozBattery is enabled by default. The Battery API is currently supported on Android, Windows, and Linux with UPower installed. Support for MacOS is available starting with Firefox 18. Firefox also provides support for the deprecated navigator.battery.
無効 From version 52: this feature is behind the dom.battery.enabled preference. To change preferences in Firefox, visit about:config.
完全対応 72
補足
補足 From this version onwards, BatteryManager is only available in chrome/privileged code.
IE 未対応 なしOpera 完全対応 25Safari 未対応 なしWebView Android 完全対応 40Chrome Android 完全対応 38
補足
完全対応 38
補足
補足 Values for BatteryManager.chargingTime and BatteryManager.dischargingTime are always equal to Infinity.
Firefox Android 未対応 10 — 16
接頭辞付き
未対応 10 — 16
接頭辞付き
接頭辞付き moz のベンダー接頭辞が必要
未対応 16 — 52
補足 無効
補足 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. The Battery API is currently supported on Android, Windows, and Linux with UPower installed. Support for MacOS is available starting with Gecko 18.0 (Firefox 18.0 / Thunderbird 18.0 / SeaMonkey 2.15). Firefox also provides support for the deprecated navigator.battery.
無効 From version 16 until version 52 (exclusive): this feature is behind the dom.battery.enabled preference. To change preferences in Firefox, visit about:config.
Opera Android 完全対応 25Safari iOS 未対応 ? — ?Samsung Internet Android 完全対応 3.0
補足
完全対応 3.0
補足
補足 Values for BatteryManager.chargingTime and BatteryManager.dischargingTime are always equal to Infinity.

凡例

完全対応  
完全対応
未対応  
未対応
非推奨。新しいウェブサイトでは使用しないでください。
非推奨。新しいウェブサイトでは使用しないでください。
実装ノートを参照してください。
実装ノートを参照してください。
ユーザーが明示的にこの機能を有効にしなければなりません。
ユーザーが明示的にこの機能を有効にしなければなりません。
使用するには、ベンダー接頭辞または異なる名前が必要です。
使用するには、ベンダー接頭辞または異なる名前が必要です。

関連情報