Is it really intentional that the same promise and battery manager are created per browsing context, instead of, say, per Document, or per Window?
<!DOCTYPE html>
<iframe src="about:blank"></iframe>
<script>
"use strict";
const iframe = document.querySelector("iframe");
const originalNavigator = iframe.contentWindow.navigator;
const originalPromise = navigator.getBattery();
promise.then(originalManager => {
iframe.onload = () => {
// As expected, navigator changes:
assert(iframe.contentWindow.navigator !== originalNavigator);
// But the battery status promise does not!?!
assert(iframe.contentWindow.navigator.getBattery() === originalPromise);
// worse:
iframe.contentWindow.navigator.getBattery().then(manager => {
// the manager stays the same!!
assert(manager === originalManager);
// which means its prototype chain is broken!?
assert(manager.__proto__ !== iframe.contentWindow.BatteryManager.prototype);
assert(!(manager instanceof iframe.contentWindow.BatteryManager));
});
};
iframe.src = "http://example.com";
});
// in fact, it's impossible to every have something be `instanceof BatteryManager`, even
// without iframe shenanigans, unless you are executing code in the initial about:blank document:
if (document.URL !== "about:blank" || document.history.length > 0) {
navigator.getBattery().then(manager => {
assert(!(manager instanceof BatteryManager));
});
}
This seems very unlikely to be correct.
I notice this spec is going for PR. Is this behavior interoperable across multiple implementations?