-
Notifications
You must be signed in to change notification settings - Fork 522
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Cannot track intersection with an iframe's viewport #372
Comments
AMP documents would benefit from this. In many cases, content within AMP is rendered within an iframe. The lack of support for this use-case means AMP can't use IntersectionObserver for such situations. |
The proposal as stated would be a change of semantics without any IDL change, meaning it's technically not backwards-compatible. However, @szager-chromium and I agree that there seems to be no good use-case for supplying an explicit root that is a scrolling element without such a clip, so we expect usage of the API in this mode to be almost non-existent. |
Also, there is an easy workaround if the other behavior is desired: make sure the element is the scrolling element, and observe relative to . |
Copying from an email thread: Off-hand the idea seems fine, I agree this is a really unfortunate limitation. It seems unfortunate to change the semantics of the root option though... Maybe we should extend to allow That'd make I haven't thought it through all that much though, but given the It seems it'd cause confusion / subtle bugs either way though. |
FYI, we landed this change behind a flag in chromium: https://chromium-review.googlesource.com/c/chromium/src/+/1865257 In this implementation, the (root == document.scrollingElement) check happens every time we run the intersection algorithm. We can still change this if we decide that { root: document } or { root: window } makes more sense. My objection to that proposal is that it's simplifying if root can be an Element rather than a Node, but I don't feel especially strongly about it. I would be surprised if using scrollingElement broke any sites, but I suppose we can run a experiment to measure it. |
Can you elaborate? If you mean on the IDL level, you can use "unions" on IDL (so I still think scrollingelement is not great due to the quirks mode stuff, and I think it's a bug that you call cc @bzbarsky in case he has opinions. |
I think relying on |
What about documentElement? The IDL does get kinda messy if we have to use a union type. |
Prettiness of IDL is dead last in the priority of constituencies. I'd be a lot more interested in what developers think about the options than in how pretty the IDL is.. |
OK, I will put together a patch based on accepting a Document as root and see how gnarly it gets. |
This implements a behavioral change as described in: w3c/IntersectionObserver#372 If the 'root' argument to the IntersectionObserver constructor is a Document, then the observer will clip to the Document's root scroller. For the top Document, this is the same behavior as the implicit root. For an iframe Document, this is new behavior which is unobtainable by other means. BUG=1015183 Change-Id: I234bfce28ab954bb15b8d157bc22ee2d2469d5e4
This issue has been getting a good deal of developer attention, so I'd like to move towards finalizing a spec change. It sounds like the behavior of accepting {root: document} is the most popular and palatable option. Any objections or other comments? |
This implements a behavioral change as described in: w3c/IntersectionObserver#372 If the 'root' argument to the IntersectionObserver constructor is a Document, then the observer will clip to the Document's root scroller. For the top Document, this is the same behavior as the implicit root. For an iframe Document, this is new behavior which is unobtainable by other means. BUG=1015183 Change-Id: I234bfce28ab954bb15b8d157bc22ee2d2469d5e4
Any thoughts how to feature detect this new functionality? E.g. by UA? With
This error appears to fire consistently across browsers but not sure if it's technically spec behavior. |
This implements a behavioral change as described in: w3c/IntersectionObserver#372 If the 'root' argument to the IntersectionObserver constructor is a Document, then the observer will clip to the Document's root scroller. For the top Document, this is the same behavior as the implicit root. For an iframe Document, this is new behavior which is unobtainable by other means. BUG=1015183 Change-Id: I234bfce28ab954bb15b8d157bc22ee2d2469d5e4
This implements a behavioral change as described in: w3c/IntersectionObserver#372 If the 'root' argument to the IntersectionObserver constructor is a Document, then the observer will clip to the Document's root scroller. For the top Document, this is the same behavior as the implicit root. For an iframe Document, this is new behavior which is unobtainable by other means. BUG=1015183 Change-Id: I234bfce28ab954bb15b8d157bc22ee2d2469d5e4
This implements a behavioral change as described in: w3c/IntersectionObserver#372 If the 'root' argument to the IntersectionObserver constructor is a Document, then the observer will clip to the Document's root scroller. For the top Document, this is the same behavior as the implicit root. For an iframe Document, this is new behavior which is unobtainable by other means. BUG=1015183 Change-Id: I234bfce28ab954bb15b8d157bc22ee2d2469d5e4 Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2003750 Reviewed-by: Chris Harrelson <chrishtr@chromium.org> Reviewed-by: vmpstr <vmpstr@chromium.org> Commit-Queue: Stefan Zager <szager@chromium.org> Cr-Commit-Position: refs/heads/master@{#734268}
This implements a behavioral change as described in: w3c/IntersectionObserver#372 If the 'root' argument to the IntersectionObserver constructor is a Document, then the observer will clip to the Document's root scroller. For the top Document, this is the same behavior as the implicit root. For an iframe Document, this is new behavior which is unobtainable by other means. BUG=1015183 Change-Id: I234bfce28ab954bb15b8d157bc22ee2d2469d5e4 Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2003750 Reviewed-by: Chris Harrelson <chrishtr@chromium.org> Reviewed-by: vmpstr <vmpstr@chromium.org> Commit-Queue: Stefan Zager <szager@chromium.org> Cr-Commit-Position: refs/heads/master@{#734268}
This implements a behavioral change as described in: w3c/IntersectionObserver#372 If the 'root' argument to the IntersectionObserver constructor is a Document, then the observer will clip to the Document's root scroller. For the top Document, this is the same behavior as the implicit root. For an iframe Document, this is new behavior which is unobtainable by other means. BUG=1015183 Change-Id: I234bfce28ab954bb15b8d157bc22ee2d2469d5e4 Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2003750 Reviewed-by: Chris Harrelson <chrishtr@chromium.org> Reviewed-by: vmpstr <vmpstr@chromium.org> Commit-Queue: Stefan Zager <szager@chromium.org> Cr-Commit-Position: refs/heads/master@{#734268}
@choumx I think it's pretty safe to rely on TypeError, especially if you use a completely simple and inert IntersectionObserver construction: var document_root_supported = true; Because the IDL for the 'root' argument changes from "Element?" to "(Element or Document)?", every browser should catch it in their bindings layer. |
…gument to constructor, a=testonly Automatic update from web-platform-tests [IntersectionObserver] Allow Document argument to constructor This implements a behavioral change as described in: w3c/IntersectionObserver#372 If the 'root' argument to the IntersectionObserver constructor is a Document, then the observer will clip to the Document's root scroller. For the top Document, this is the same behavior as the implicit root. For an iframe Document, this is new behavior which is unobtainable by other means. BUG=1015183 Change-Id: I234bfce28ab954bb15b8d157bc22ee2d2469d5e4 Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2003750 Reviewed-by: Chris Harrelson <chrishtr@chromium.org> Reviewed-by: vmpstr <vmpstr@chromium.org> Commit-Queue: Stefan Zager <szager@chromium.org> Cr-Commit-Position: refs/heads/master@{#734268} -- wpt-commits: aebf5e72a429c448637c388512bcadd4d4e3fa65 wpt-pr: 21222
…gument to constructor, a=testonly Automatic update from web-platform-tests [IntersectionObserver] Allow Document argument to constructor This implements a behavioral change as described in: w3c/IntersectionObserver#372 If the 'root' argument to the IntersectionObserver constructor is a Document, then the observer will clip to the Document's root scroller. For the top Document, this is the same behavior as the implicit root. For an iframe Document, this is new behavior which is unobtainable by other means. BUG=1015183 Change-Id: I234bfce28ab954bb15b8d157bc22ee2d2469d5e4 Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2003750 Reviewed-by: Chris Harrelson <chrishtr@chromium.org> Reviewed-by: vmpstr <vmpstr@chromium.org> Commit-Queue: Stefan Zager <szager@chromium.org> Cr-Commit-Position: refs/heads/master@{#734268} -- wpt-commits: aebf5e72a429c448637c388512bcadd4d4e3fa65 wpt-pr: 21222
…gument to constructor, a=testonly Automatic update from web-platform-tests [IntersectionObserver] Allow Document argument to constructor This implements a behavioral change as described in: w3c/IntersectionObserver#372 If the 'root' argument to the IntersectionObserver constructor is a Document, then the observer will clip to the Document's root scroller. For the top Document, this is the same behavior as the implicit root. For an iframe Document, this is new behavior which is unobtainable by other means. BUG=1015183 Change-Id: I234bfce28ab954bb15b8d157bc22ee2d2469d5e4 Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2003750 Reviewed-by: Chris Harrelson <chrishtrchromium.org> Reviewed-by: vmpstr <vmpstrchromium.org> Commit-Queue: Stefan Zager <szagerchromium.org> Cr-Commit-Position: refs/heads/master{#734268} -- wpt-commits: aebf5e72a429c448637c388512bcadd4d4e3fa65 wpt-pr: 21222 UltraBlame original commit: ec3f916509c9a7ac7e2d170db1a1d1e6ac027d55
…gument to constructor, a=testonly Automatic update from web-platform-tests [IntersectionObserver] Allow Document argument to constructor This implements a behavioral change as described in: w3c/IntersectionObserver#372 If the 'root' argument to the IntersectionObserver constructor is a Document, then the observer will clip to the Document's root scroller. For the top Document, this is the same behavior as the implicit root. For an iframe Document, this is new behavior which is unobtainable by other means. BUG=1015183 Change-Id: I234bfce28ab954bb15b8d157bc22ee2d2469d5e4 Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2003750 Reviewed-by: Chris Harrelson <chrishtrchromium.org> Reviewed-by: vmpstr <vmpstrchromium.org> Commit-Queue: Stefan Zager <szagerchromium.org> Cr-Commit-Position: refs/heads/master{#734268} -- wpt-commits: aebf5e72a429c448637c388512bcadd4d4e3fa65 wpt-pr: 21222 UltraBlame original commit: ec3f916509c9a7ac7e2d170db1a1d1e6ac027d55
https://bugs.webkit.org/show_bug.cgi?id=208047 Patch by Frederic Wang <fwang@igalia.com> on 2020-03-06 Reviewed by Simon Fraser. LayoutTests/imported/w3c: * web-platform-tests/intersection-observer/document-scrolling-element-root-expected.txt: Update expectation now that the test passes. Source/WebCore: This patch introduces a recent enhancement to the Intersection Observer specification: the root initialization parameter can be explicitly be set to a Document. The typical use case is when document is an iframe. See w3c/IntersectionObserver#372 This patch also updates the way Element's intersection observer data is handled so that it is more consistent with the explicit Document root case introduced here. Test: imported/w3c/web-platform-tests/intersection-observer/document-scrolling-element-root.html * dom/Document.cpp: (WebCore::Document::~Document): Notify observers about our desctruction. (WebCore::Document::updateIntersectionObservations): Use new method name. This does not require null-check because ensureIntersectionObserverData() has been called in IntersectionObserver::observe(). (WebCore::Document::ensureIntersectionObserverData): Return reference to intersection observer data for this document, creating one if it does not exist. * dom/Document.h: Add new intersection observer data, used for documents that are explicit intersection observer roots. (WebCore::Document::intersectionObserverDataIfExists): Return pointer to intersection observer data or null if it does not exist. * dom/Element.cpp: (WebCore::Element::didMoveToNewDocument): Use new method name. (WebCore::Element::disconnectFromIntersectionObservers): Ditto and null-check weak refs. (WebCore::Element::intersectionObserverDataIfExists): Rename method to match Document's one and be more explicit that it will be null if it does not exist. (WebCore::Element::intersectionObserverData): Renamed. * dom/Element.h: Renamed. * html/LazyLoadImageObserver.cpp: (WebCore::LazyLoadImageObserver::intersectionObserver): Initialize with a WTF::Optional after API change. * page/IntersectionObserver.cpp: (WebCore::IntersectionObserver::create): Pass a Node* root, which can be null (implicit root), Document* or Element* (explicit roots). This is determined from init.root. (WebCore::IntersectionObserver::IntersectionObserver): Handle the case of explicit Document root. (WebCore::IntersectionObserver::~IntersectionObserver): Ditto and update method name for the explicit Element case. Note that in both explicit root cases the corresponding ensureIntersectionObserverData() method had been called in the constructor so they can be safely deferenced. (WebCore::IntersectionObserver::removeTargetRegistration): Use new method name. * page/IntersectionObserver.h: Update comment and code now that explicit root is a Node* and IntersectionObserver::Init::root is either an Element or a Document or null. (WebCore::IntersectionObserver::root const): Ditto. (): Deleted. * page/IntersectionObserver.idl: Update IDL to match the spec IntersectionObserver::root is a nullable Node and IntersectionObserverInit::root a nullable Element or Document. Canonical link: https://commits.webkit.org/221607@main git-svn-id: https://svn.webkit.org/repository/webkit/trunk@257976 268f45cc-cd09-0410-ab3c-d52691b4dbfc
Some Safari versions now pass this feature-detection but have a bug in the implementation. Callbacks are not invoked when the target intersects with the viewport: https://bugs.webkit.org/show_bug.cgi?id=224324 |
The implicit root refers to the top window'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.
I think document.scrollingElement ought to be treated specially when it's used as the root of an IntersectionObserver: it should be treated as measuring intersection with the document window's scrolling viewport.
The text was updated successfully, but these errors were encountered: