navigator.getBattery() is the entry point to the Battery Status API. Learn how to get a BatteryManager, read charging and level, listen for chargingchange, use HTTPS, and try five beginner examples.
01
Kind
Method
02
Returns
Promise<BatteryManager>
03
Status
Limited availability
04
Context
Secure (HTTPS)
05
API family
Battery Status API
06
Key fields
charging · level
Fundamentals
Introduction
Laptops and phones have a battery. Your page can optionally read a simple status snapshot — is it charging? how full is it? — through navigator.getBattery().
The method does not return the numbers directly. It returns a Promise that resolves to a BatteryManager object. From there you read properties and listen for change events.
💡
Use for UX, not tracking
Good uses: pause heavy animations on low battery, show a gentle “plug in” hint. Bad uses: fingerprinting or forcing behavior when the API is missing.
Concept
Understanding the getBattery() Method
No parameters — call navigator.getBattery().
Resolves to BatteryManager — properties include charging, level, chargingTime, dischargingTime.
Events — e.g. chargingchange, levelchange, time-change events.
Secure context — HTTPS / localhost required in modern Chromium.
Permissions-Policy — may be gated by the battery directive.
Limited support — missing in some browsers for privacy; always feature-detect.
Foundation
📝 Syntax
General form of the method:
JavaScript
navigator.getBattery()
Parameters
None.
Return value
A Promise that fulfills with a BatteryManager object.
Four facts to remember about navigator.getBattery().
Returns
Promise
BatteryManager
Availability
Limited
Not Baseline
Context
HTTPS
Secure required
Level
0.0–1.0
Multiply by 100
Compare
📋 BatteryManager Properties
Property
Meaning
charging
Boolean — currently charging?
level
Number 0–1 — remaining charge fraction
chargingTime
Seconds until full (or Infinity / 0 depending on state)
dischargingTime
Seconds until empty (or Infinity when charging / unknown)
Hands-On
Examples Gallery
Examples follow MDN Battery Status API patterns. Prefer Try It Yourself — many browsers omit the API, and desktops without a battery may report always-charging / full.
navigator.getBattery() implements the Battery Status API and is not Baseline. Chromium browsers support it in secure contexts; Firefox removed it for privacy; Safari support is limited or absent. Always feature-detect, use HTTPS, and keep core UX independent of battery data.
✓ Limited availability · Not Baseline
Navigator.getBattery()
Promise → BatteryManager — charging, level, and change events.
LimitedNot Baseline
Google ChromeBattery Status · secure context (from Chrome 103)
Limited
Microsoft EdgeFollow Chromium Battery Status / HTTPS
Limited
OperaFollow Chromium where available
Limited
Mozilla FirefoxRemoved for privacy — feature-detect
Unavailable
Apple SafariTypically unavailable — feature-detect
Unavailable
Internet ExplorerNo Battery Status / getBattery
Unavailable
getBattery()Limited
Bottom line: Detect getBattery, await BatteryManager on HTTPS, handle rejections, and never require battery status for essential features.
Wrap Up
Conclusion
navigator.getBattery() opens the Battery Status API with a Promise for a BatteryManager. Detect support, use HTTPS, read charging and level, listen for changes, and treat battery insights as optional UX — never as a hard dependency.
It returns a Promise that resolves to a BatteryManager object with charging state, battery level (0–1), charging/discharging times, and events such as chargingchange and levelchange.
No. MDN does not mark it Deprecated, Experimental, or Non-standard. It is Limited availability (not Baseline), requires a secure context in modern Chrome, and may be missing for privacy reasons in some browsers. No status banner is required.
Yes in supporting Chromium browsers since Chrome 103: getBattery() is a secure-context feature (HTTPS or localhost). Calling it from an insecure context can throw SecurityError.
A number from 0.0 to 1.0 representing remaining charge — for example 0.75 means about 75%.
No. Desktops without a battery, privacy-restricted browsers (notably Firefox removed the API), and missing Permissions-Policy: battery can block or omit it. Always feature-detect and handle Promise rejection.
No. Battery status is for helpful UX (pause heavy work on low battery), not fingerprinting. Prefer privacy-respecting, optional enhancements.
Did you know?
On many desktop machines without a battery (or with the OS reporting “always plugged in”), charging may stay true and level may stay at 1. Always treat those values as hints, not absolute truth.