[whatwg/fullscreen] document.fullscreenElement in scroll event after entering fullscreen matters for compat (#74)

In https://crbug.com/680467 there is fallout from aligning the timing of `document.fullscreenElement` and `fullscreenchange` event with animation frames in https://crbug.com/402376.

On https://twitter.com/BCCI, if ones scrolls down a bit and plays a video in fullscreen, the iframe the video is in is removed from the document, leaving things in a broken-looking state. I [speculate](https://bugs.chromium.org/p/chromium/issues/detail?id=680467#c18) that this code tries to remove video that have scrolled out of view.

The crucial change is that in the scroll event fired after entering fullscreen, the fullscreen steps have not yet run, so to the page it looks like the page has simply been resized, causing a scroll.

I [investigated](https://bugs.chromium.org/p/chromium/issues/detail?id=680467#c20) current behavior:
* In Edge 14, the scroll event is fired after the fullscreenchange event, and so naturally the fullscreen element has already changed.
* In Firefox 54, the scroll event is fired before the fullscreenchange event when the fullscreen element has not yet changed.  For some reason, it still does not get this bug on Twitter.
* In Chrome 55 (before my changes) and Safari 10, the scroll event is fired before the fullscreenchange event, and yet the fullscreen element has already changed.

I can see a few alternatives here, in rough order of preference:
* Apply the fullscreen state changes immediately on resize and delay only the events until animation frame timing.
* Tweak the order of scroll and fullscreen change events in https://html.spec.whatwg.org/multipage/webappapis.html#event-loop-processing-model
* Introduce a `document.pendingFullscreenElement` that could be used by Twitter to avoid this problem.
* Ask Twitter to keep track of whether they are entering fullscreen themselves to avoid this.
* Suppress scroll events in fullscreen entirely.

@upsuper @jernoble @aliams

-- 
You are receiving this because you are subscribed to this thread.
Reply to this email directly or view it on GitHub:
https://github.com/whatwg/fullscreen/issues/74

Received on Thursday, 26 January 2017 12:15:00 UTC