battery api 'chargingchange' event is broken

RESOLVED INCOMPLETE

Status

()

Core
DOM
RESOLVED INCOMPLETE
2 years ago
10 months ago

People

(Reporter: dietrich, Assigned: jdm)

Tracking

({regression, regressionwindow-wanted})

Firefox Tracking Flags

(Not tracked)

Details

(Whiteboard: btpp-active)

Attachments

(1 attachment)

(Reporter)

Description

2 years ago
navigator.getBattery().then(function(battery) {
  battery.addEventListener('chargingchange', function(e) {
    console.log(e);
  });
});

1. doesn't fire when unplugging power

2. when plug back in, get 4 events - two for each state.

Tested release, dev edition and nightly.
Testing on 47.0a2 and OSX 10.11.3, on a mid-2013 Macbook Pro, I don't get _any_ events at all when removing and pluggin in power.

JSBin used to test: http://jsbin.com/luvuwevowa/1/edit?js,console
Testing on 48.0a1 (Nightly 2016-03-22) and Arch Linux, on a Thinkpad x240, I also don't get _any_ events. I'm using the same JSBin that :Osmose posted. I also tried similar code in a localhost webserver.
(Reporter)

Comment 3

2 years ago
Andrew, can you help to get this into the right hands.
Flags: needinfo?(overholt)
(Reporter)

Updated

2 years ago
Keywords: regression, regressionwindow-wanted
Summary: battery api 'chargingchange' event is broken on mac os x on a macbook → battery api 'chargingchange' event is broken
snorp said he could take a look. A regression window would be great.
Flags: needinfo?(overholt) → needinfo?(snorp)
I see a bunch of text in the console when I try http://jsbin.com/luvuwevowa/1/edit?js,console in Fennec nightly on a Nexus 5.
The example in comment #5 works fine for me on Fennec, so I'm not interested anymore :)
Flags: needinfo?(snorp)
jdm said he'd investigate and at least get a regression window.
Flags: needinfo?(josh)
Created attachment 8734788 [details]
screenshoot.jpg

Firefox: 48.0a1, Build ID  20160322030417
User Agent:  Mozilla/5.0 (Macintosh; Intel Mac OS X 10.11; rv:48.0) Gecko/20100101 Firefox/48.0

Hi Dietrich,

I have tested this issue on the latest Firefox (45.0.1) release, latest Nightly (48.0a1) build, but I could not reproduce it using the provided test case from comment 1. I have unpluged the charger and an event appeared in the console. When I plunged the charger back in, another event appeared in the console (see attachment). Tested on a MacBook Pro. 
On what OS version did you encounter this problem?

Thanks,
Cosmin.
Flags: needinfo?(dietrich)
(Reporter)

Comment 9

2 years ago
System profile: https://i.imgur.com/71p1gJ0.png

Plug-back-in is when I get all events. I get nothing when unplugging. Tested on Release, Dev Edition, Nightly.
Flags: needinfo?(dietrich)
Hi Dietrich,

Can you please retest this using latest Firefox release and latest Nightly build (https://nightly.mozilla.org/) and report back the results ? When doing this, please use a new clean Firefox profile, maybe even safe mode, to eliminate custom settings as a possible cause (https://goo.gl/PNe90E). 

Thanks,
Cosmin.
Flags: needinfo?(dietrich)
(Assignee)

Comment 11

2 years ago
I could reproduce the problem using the provided testcase on OS X 10.9.5 in nightly.
(Reporter)

Comment 12

2 years ago
Repro'd in comment #11, removing NI. Thanks Josh.
Flags: needinfo?(dietrich)
Component: General → DOM
Product: Firefox → Core
(Assignee)

Comment 13

2 years ago
I looked at this a bit more, and I'm not certain on whether there's actually a problem. Specifically, if I wait long enough with the power either disconnected or reconnected, I eventually see a notification for the new state. I suspect this corresponds with the level changing (ie. 91% -> 90%, or the reverse). This may be working as intended?
Flags: needinfo?(josh)
(Reporter)

Comment 14

2 years ago
Thanks Josh. The docs on MDN don't really say that though. And perhaps they're wrong?

Here are the docs for the event, which say it fires when battery.charging value changes:

https://developer.mozilla.org/en-US/docs/Web/Events/chargingchange

Battery.charging is a bool indicating whether battery is currently charging or not:

https://developer.mozilla.org/en-US/docs/Web/API/BatteryManager/charging

Given that, I'd expect that unplugging the power source would fire the event immediately, and same for plugging in.
I tried to replicate comment 13:

1. Starting at 100% charge, I loaded the JSBin page. No event.

2. I unplugging my power, started playing a Youtube video.

3. About 500 years later[1], the remains of my corpse, still dutifully watching the battery level, notices the battery level drop to 99%. It's like the laptop knows it's being watched or something. No events.

4. After waiting a few minutes at 99% I plug the cord back in. The battery indicator shows a lightning bolt over an unfilled battery to signify charging has started. No events.

5. Within 10 seconds the battery indicator changes to a filled battery with a lightning bolt, and a chargingcharge event gets logged.

6. I remove the charging cable. Icon goes back to a full battery with no lightning bolt. After a 10-20 second delay, an event is logged.

After that I get the same results from steps 5 and 6 by removing and reattaching the power cable. Specifically, the events being logged when the cable is plugged in correspond with the battery icon going from an unfilled battery with a lightning bolt to a filled battery with a lightning bolt. The charge number fluctuated between 99% and 100% during these tests, but I didn't observe any pattern between the charge number changing any the event triggering. I remain unable to trigger events with my battery at 100%.

FWIW my read is that it might be correctly detecting the battery charging, and isn't detecting the laptop using the cable as a power source instead of the battery. Although that doesn't match up with the results in comment 1.

[1] Okay so like 7 minutes but jeez.
Assignee: nobody → josh
Whiteboard: btpp-active

Comment 16

10 months ago
Battery API is no longer supported.
Status: NEW → RESOLVED
Last Resolved: 10 months ago
Resolution: --- → INCOMPLETE
You need to log in before you can comment on or make changes to this bug.