Intent to Ship: IntersectionObserver accepting Document as root

85 views
Skip to first unread message

Stefan Zager

unread,
Jan 22, 2020, 4:42:06 PM1/22/20
to blink-dev
Contact email: sza...@chromium.org

Explainer:
IntersectionObserver explainer

Summary:
An IntersectionObserver can either track an "explicit" root element, or else it tracks the "implicit" root, which is the top-level document's scrolling viewport; but there is currently no way to track the intersection of an element inside an iframe with the iframe window's scrolling viewport. We might try something like this (running in the iframe's context):

new IntersectionObserver(callback, {root: document.scrollingElement})

... but that doesn't work, because document.scrollingElement.getBoundingClientRect() gives you the full size of the document's content, not the window's scrolling viewport.

With the proposed change, an IntersectionObserver can take a Document as its root; in which case intersections will be calculated with the Document's scrolling viewport.

Is this feature supported on all six Blink platforms (Windows, Mac, Linux, Chrome OS, Android, and Android WebView)?
Yes

Stefan Zager

unread,
Jan 22, 2020, 6:36:34 PM1/22/20
to Stefan Zager, blink-dev
Forgot some sections...

Why no TAG review?
This is a relatively minor and uncontroversial change to an existing API, and it does not modify any existing behavior.

Testing plan
There is a WPT for the new behavior.

Feature detection / interop
This can be detected by attempting to create an IntersectionObserver with a document root:

var intersection_observer_supports_document_root = true;
try {
  new IntersectionObserver(() => {}, {root: document});
} catch {
  intersection_observer_supports_document_root = false;
}

Stefan Zager

unread,
Jan 22, 2020, 7:29:03 PM1/22/20
to Stefan Zager, blink-dev

Philip Jägenstedt

unread,
Jan 23, 2020, 1:23:04 PM1/23/20
to Stefan Zager, blink-dev
This seems like a fairly minor change, bypassing the intent process in this case would have been OK IMHO.

LGTM1 assuming that https://github.com/w3c/IntersectionObserver/pull/411 gets merged and browser bugs filed.

--
You received this message because you are subscribed to the Google Groups "blink-dev" group.
To unsubscribe from this group and stop receiving emails from it, send an email to blink-dev+...@chromium.org.
To view this discussion on the web visit https://groups.google.com/a/chromium.org/d/msgid/blink-dev/CAHOQ7J8rS8r-xM_7V5_1iFxRc_Cv068J7CSig7nCNd0LLpkqAg%40mail.gmail.com.

Daniel Bratell

unread,
Jan 23, 2020, 2:02:01 PM1/23/20
to Philip Jägenstedt, Stefan Zager, blink-dev

Chris Harrelson

unread,
Jan 23, 2020, 2:24:59 PM1/23/20
to Philip Jägenstedt, Stefan Zager, blink-dev
On Thu, Jan 23, 2020 at 10:23 AM Philip Jägenstedt <foo...@chromium.org> wrote:
This seems like a fairly minor change, bypassing the intent process in this case would have been OK IMHO.

I agree that this one is relatively minor. I recommended an intent-to-ship for this feature because (a) it unlocks an important new use case (measuring visibility relative to a local iframe root, for full-screen cross-origin content embedded in another frame), (b) so that it's clear to developers which Chrome version to target, and (c) so that we can encourage other browsers to implement this change. :)
 

Yoav Weiss

unread,
Jan 24, 2020, 4:36:30 AM1/24/20
to Chris Harrelson, Philip Jägenstedt, Stefan Zager, blink-dev
LGTM3 with similar conditions to Philip's.

Frédéric Wang

unread,
Feb 24, 2020, 3:56:00 AM2/24/20
to blin...@chromium.org

Chris Harrelson

unread,
Feb 24, 2020, 12:31:48 PM2/24/20
to Frédéric Wang, blink-dev
Excellent! Thanks for the update.

Reply all
Reply to author
Forward
0 new messages