While fixing some other bugs, I noticed that window.closed doesn't behave consistently for main frames vs subframes. window.close() is async-ish, so today, when we call it, we mark the window as closing and call closeWidgetSoon().
However, since this is tracked per-window, rather than per-page, given code like this:
var w = window.open();
w.document.body.appendChild(w.document.createChild('iframe'));
w.close();
console.log(w.closed);
console.log(w[0].closed);
will print:
true
false
The steps given in the spec for discarding a browsing context seem to imply that this should return true, true though: https://html.spec.whatwg.org/multipage/browsers.html#a-browsing-context-is-discarded
To make things more fun, Firefox agrees with us, but Edge returns false, true!
Spec bug: https://github.com/whatwg/html/issues/2126#issuecomment-267130700
Comment 1 by sheriffbot@chromium.org
, Feb 16 2018Status: Untriaged (was: Available)