On 10/26/16 3:30 AM, Chris Peterson wrote:
The BATTERY_STATUS_COUNT probe [4] reports over 200M battery API calls
for Firefox 49. The USE_COUNTER2_DEPRECATED_NavigatorBattery_PAGE probe
[5] reports that 6% of web pages use the Battery API, IIUC. That seems
surprisingly high given the few legitimate use cases. (Could that
counter be inadvertently triggered by web content that simply enumerates
the navigator object's properties without actually calling
navigator.getBattery()?)

In Firefox 49, the BATTERY_STATUS_COUNT thing counts actual calls to getBattery() _and_ calls to the .battery getter (it distinguishes the two, though); the latter would be affected by enumeration of Navigator but the former would not. Also, it counts only the first call for the given document, which means that 200M number is NOT inflated by multiple per-page calls.

In particular, looking at the actual histogram, we have about 105M uses of navigator.battery and 116M uses of navigator.getBattery(). Out of how many loads? See below. Also, this may somewhat undercount getBattery() calls, because the way our telemetry code is written if the page does .battery before doing .getBattery() we will count the former but not the latter. If the order is reversed we will count both.

The USE_COUNTER2_DEPRECATED_NavigatorBattery_PAGE counter counts gets of Navigator.battery and _would_ be affected by enumeration. This attibute was removed in Firefox 50 (see https://bugzilla.mozilla.org/show_bug.cgi?id=1259335 which I'm pretty sure you knew about already ;) ).

The good news is that the deprecated counter lets us answer the "out of how many loads?" question, sort of. The numbers above are out of 924 million toplevel pageloads. However, note that BATTERY_STATUS_COUNT counts per _document_, so can count multiple accesses per pageload when iframes are involved.

One way to reconcile the two sets of numbers is that the 105M _documents_ that use navigator.battery per the BATTERY_STATUS_COUNT counter corresponds to 57M _pageloads_ that use navigator.battery per the deprecated operation counter. Assuming that this ratio holds for getBattery() (may not be a good assumption), that means about 6% of pageloads also end up using getBattery(). That does seem ludicrously high.

So I decided to see what sites were doing with it. I set a breakpoint in getBattery() and tried browsing. The first site I tried loading was cnn.com, and it hit the breakpoint. It's hitting it because it's using the "boomerang" library from https://github.com/yahoo/boomerang (or one of its various clones) as far as I can tell, and https://github.com/yahoo/boomerang/blob/b70cb237c175debf1fda31ab9ae44e1cfa7996ca/plugins/memory.js#L177-L203 pokes at the battery API. Looks like it reports the battery level as part of its telemetry? The original commit that introduces that is https://github.com/yahoo/boomerang/commit/b0c41b144913338ea905f03fc28f32130c5521e5 which is not terribly informative as to _why_ that data is being collected.

Anyway, if that library is popular enough, that could account for a lot of the telemetry we see. :(

-Boris
_______________________________________________
dev-platform mailing list
dev-platform@lists.mozilla.org
https://lists.mozilla.org/listinfo/dev-platform

Reply via email to