RESOLVED FIXED 159475
Implement IntersectionObserver
https://bugs.webkit.org/show_bug.cgi?id=159475
Summary Implement IntersectionObserver
Jeffrey Gilbert
Reported 2016-07-06 10:24:10 PDT
Working draft for implementation: https://wicg.github.io/IntersectionObserver/ Intent to implement in Firefox by version 50 https://bugzilla.mozilla.org/show_bug.cgi?id=1243846 https://developer.mozilla.org/en-US/docs/Web/API/Intersection_Observer_API Chrome adopted IntersectionObserver support in version 51 https://www.chromestatus.com/feature/5695342691483648 https://chromium.googlesource.com/chromium/src/third_party/+/master/WebKit/Source/core/dom/IntersectionObserver.cpp MS Edge has committed to adopting support, but have not implemented yet https://developer.microsoft.com/en-us/microsoft-edge/platform/status/intersectionobserver https://wpdev.uservoice.com/forums/257854-microsoft-edge-developer/suggestions/13407852-intersectionobserver Rationale: Advertisements typically use Flash, frame per second counters, or costly geometry calculations within loops to determine if an ad is in view or not. The mechanisms are difficult to implement, non-standardized, and costly to web performance. The IAB, MRC, browser vendors, and web standards bodies have attempted to solve for this by introducing first the PageVisibility 2 API draft, and now splintered off from that, the IntersectionObserver API. This pattern allows for efficient event driven code to take advantage of indicators sent directly from the browser of the area of a page or more importantly sandboxed iframe which are viewable without requiring access to the parent documents information or leaking important security details. Chrome has introduced this early as a way of hastening the elimination of the Flash browser plugin as a necessary evil, which they plan to throttle by default at the end of the year. Firefox's intention is to introduce this functionality as part of version 50, currently in nightlies. Microsoft has commented to the IAB that they intend to introduce the functionality, but have not committed to a build version or date for releasing it. That leaves only Safari/Webkit based browsers left. This solves an obvious problem for advertisers and consumers/end users who want transparency and performance, respectively.
Attachments
Work in progress (118.52 KB, patch)
2016-10-28 17:54 PDT, Simon Fraser (smfr)
no flags
Step 1: Bindings support (125.24 KB, patch)
2016-10-28 20:58 PDT, Simon Fraser (smfr)
rniwa: review+
Archive of layout-test-results from ews121 for ios-simulator-wk2 (deleted)
2016-10-28 22:37 PDT, Build Bot
no flags
Work in progress patch (51.34 KB, patch)
2018-02-02 15:14 PST, Simon Fraser (smfr)
no flags
WIP (150.79 KB, patch)
2018-07-12 15:02 PDT, Ali Juma
no flags
Archive of layout-test-results from ews102 for mac-sierra (2.44 MB, application/zip)
2018-07-12 16:20 PDT, EWS Watchlist
no flags
Archive of layout-test-results from ews104 for mac-sierra-wk2 (2.81 MB, application/zip)
2018-07-12 16:36 PDT, EWS Watchlist
no flags
Archive of layout-test-results from ews112 for mac-sierra (3.18 MB, application/zip)
2018-07-12 16:59 PDT, EWS Watchlist
no flags
Archive of layout-test-results from ews125 for ios-simulator-wk2 (2.30 MB, application/zip)
2018-07-12 17:05 PDT, EWS Watchlist
no flags
Archive of layout-test-results from ews126 for ios-simulator-wk2 (2.30 MB, application/zip)
2018-07-12 19:06 PDT, EWS Watchlist
no flags
WIP (193.24 KB, patch)
2018-07-25 11:50 PDT, Ali Juma
no flags
Archive of layout-test-results from ews100 for mac-sierra (2.47 MB, application/zip)
2018-07-25 13:10 PDT, EWS Watchlist
no flags
Archive of layout-test-results from ews112 for mac-sierra (3.19 MB, application/zip)
2018-07-25 13:40 PDT, EWS Watchlist
no flags
Archive of layout-test-results from ews121 for ios-simulator-wk2 (2.24 MB, application/zip)
2018-07-25 13:49 PDT, EWS Watchlist
no flags
WIP (211.03 KB, patch)
2018-08-08 11:46 PDT, Ali Juma
no flags
Archive of layout-test-results from ews123 for ios-simulator-wk2 (2.35 MB, application/zip)
2018-08-08 13:45 PDT, EWS Watchlist
no flags
WIP (100.64 KB, patch)
2018-10-09 14:59 PDT, Ali Juma
ews-watchlist: commit-queue-
Archive of layout-test-results from ews121 for ios-simulator-wk2 (2.57 MB, application/zip)
2018-10-09 18:03 PDT, EWS Watchlist
no flags
Jeffrey Gilbert
Comment 1 2016-08-04 10:15:31 PDT
Update: Chrome has a working implementation out now as of Chrome 51. The next Chrome release will also introduce a throttling mechanism on Flash which will greatly impact Flash functionality across site publishers. Linked in the comments are some of the implementation details for the Chrome feature. Safari currently has no ability to report behavior using Flash as it has already been throttled and when it's used, it's inaccurate upon initial page load until the Flash player has been scrolled in and out of view so it's forced to change state. Geometric polling does work, but it's an expensive operation to call from javascript resulting in reduced battery life from higher cpu usage. Billing standards for advertisements are rapidly moving toward viewability based guarantees, so this mechanism for measurement and the impact of these calls will not be reduced until the implementation of this spec goes out in major webkit browsers(specifically Safari, mobile Safari, and embedded webviews).
Simon Fraser (smfr)
Comment 2 2016-10-28 17:54:37 PDT
Created attachment 293262 [details] Work in progress
Simon Fraser (smfr)
Comment 3 2016-10-28 20:58:13 PDT
Created attachment 293271 [details] Step 1: Bindings support
Simon Fraser (smfr)
Comment 4 2016-10-28 21:06:05 PDT
Ryosuke Niwa
Comment 5 2016-10-28 22:16:46 PDT
Oh it looks like the bots are choking on an unrelated test that's temporarily broken.
Ryosuke Niwa
Comment 6 2016-10-28 22:21:07 PDT
Comment on attachment 293271 [details] Step 1: Bindings support View in context: https://bugs.webkit.org/attachment.cgi?id=293271&action=review > LayoutTests/intersection-observer/intersection-observer-entry-interface.html:4 > +<head> > +<script src="../resources/js-test-pre.js"></script> > +</head> Can we use testharness.js instead? Ideally, we'd upstream these tests to web-platform-tests. > LayoutTests/intersection-observer/intersection-observer-entry-interface.html:10 > + if (window.internals) > + internals.settings.setIntersectionObserverEnabled(true); For custom elements & shadow DOM, I unconditionally enabled them all in DRT & WTR.
Build Bot
Comment 7 2016-10-28 22:37:19 PDT Comment hidden (obsolete)
Build Bot
Comment 8 2016-10-28 22:37:25 PDT Comment hidden (obsolete)
Simon Fraser (smfr)
Comment 9 2016-10-31 15:16:53 PDT Comment hidden (obsolete)
Sebastian Zartner
Comment 10 2017-11-10 03:23:22 PST
It looks like all other major browsers already shipped support for this API, already. Simon, can you give a status update on this, please? Sebastian
João Nadais
Comment 11 2017-11-25 07:26:50 PST
Is there any estimation for what version will this support be added in WebKit? All other browsers already support it...
Simon Fraser (smfr)
Comment 12 2018-02-02 15:14:29 PST
Created attachment 333008 [details] Work in progress patch
Mandy Pettt
Comment 14 2018-05-29 12:54:38 PDT
dvertisements typically use Flash, frame per second counters, or costly geometry calculations within loops to determine if an ad is in view or not. The mechanisms are difficult to implement, non-standardized, and costly to web performance. https://spinbikes218477221.wordpress.com/
William J. Edney
Comment 15 2018-05-30 11:25:32 PDT
At the risk of bugging Simon, any thoughts on getting the WIP to a final patch? Would beer help? :-).
Paul Knight
Comment 16 2018-06-01 17:46:02 PDT
(In reply to William J. Edney from comment #15) > At the risk of bugging Simon, any thoughts on getting the WIP to a final > patch? Would beer help? :-). I would also buy Simon a big old burger if we could get this in Safari
Paul Knight
Comment 17 2018-06-01 17:47:18 PDT
Is there any idea of when this is likely to land in Safari? It's such a great API.
Danyao Wang
Comment 18 2018-06-20 08:03:50 PDT
Thanks for starting to work on this, Simon! I ran your patch through the Intersection Observer WPT and a few demo sites. These seem to be the outstanding issues: 1. Notifications don't seem to be firing, either when scrolling or when new element is added to the DOM (see assert_equals failures on entries.length) 2. Should be able to observe target in a same-origin iframe, but throws WrongDocumentException instead 3. rootMargin parsing is not up-to-spec. Specifically, step 5 doesn't seem to be implemented. 4. Doesn't throw expected exceptions on invalid constructor arguments 5. (seen in demo) IntersectionObserverEntry.isIntersecting attribute is not implemented (from https://hacks.mozilla.org/2017/08/intersection-observer-comes-to-firefox/) 6. (seen in demo) When user scrolls using the trackpad or by holding and dragging the scrollbar, intersection events are not fired as frequently when threshold is fine grained. This is clear for the top-most box in the MDN demo: Safari video vs. Chrome video. Here's the WPT result summary: https://danyao.github.io/intersection-observer/report/all.html#test-file-20 Is there anything I can help to land all or parts of this patch?
Darin Adler
Comment 19 2018-07-06 09:09:04 PDT
I don’t think Simon is going to be picking this up any time soon, so it would be great if someone else did. A good start would be to add tests to the patch to cover the issues mentioned above, then rebase the patch, and refine until all the tests pass. If you do work on it, please communicate with others here about the fact that you are doing so, and attach work in progress patches from time to time so someone else can pick up where you left off if you drop it.
Ali Juma
Comment 20 2018-07-06 09:28:50 PDT
(In reply to Darin Adler from comment #19) > I don’t think Simon is going to be picking this up any time soon, so it > would be great if someone else did. > > A good start would be to add tests to the patch to cover the issues > mentioned above, then rebase the patch, and refine until all the tests pass. > If you do work on it, please communicate with others here about the fact > that you are doing so, and attach work in progress patches from time to time > so someone else can pick up where you left off if you drop it. Sounds good, I'll upload WIP patches as I go along.
Ali Juma
Comment 21 2018-07-12 15:02:45 PDT
Ali Juma
Comment 22 2018-07-12 15:09:15 PDT
(In reply to Ali Juma from comment #21) > Created attachment 344885 [details] > WIP This passes 16/24 web platform tests (the web platform tests cover all the issues mentioned in Comment 18). The main work still to be done includes: 1) Dealing with zero-area intersections 2) Cross-document observation 3) Checking if behavior with pinch zoom and page zoom is reasonable 4) Correctly handling lifetime of IntersectionObservers and their associated roots and targets (so they're not destroyed too early, but also don't leak) (1) and (2) are covered by the 8 remaining web platform test failures.
EWS Watchlist
Comment 23 2018-07-12 16:20:37 PDT Comment hidden (obsolete)
EWS Watchlist
Comment 24 2018-07-12 16:20:39 PDT Comment hidden (obsolete)
EWS Watchlist
Comment 25 2018-07-12 16:36:15 PDT Comment hidden (obsolete)
EWS Watchlist
Comment 26 2018-07-12 16:36:17 PDT Comment hidden (obsolete)
EWS Watchlist
Comment 27 2018-07-12 16:59:26 PDT Comment hidden (obsolete)
EWS Watchlist
Comment 28 2018-07-12 16:59:28 PDT Comment hidden (obsolete)
EWS Watchlist
Comment 29 2018-07-12 17:05:51 PDT Comment hidden (obsolete)
EWS Watchlist
Comment 30 2018-07-12 17:05:54 PDT Comment hidden (obsolete)
EWS Watchlist
Comment 31 2018-07-12 19:06:49 PDT Comment hidden (obsolete)
EWS Watchlist
Comment 32 2018-07-12 19:06:51 PDT Comment hidden (obsolete)
Ali Juma
Comment 33 2018-07-25 11:50:14 PDT Comment hidden (obsolete)
EWS Watchlist
Comment 34 2018-07-25 13:10:18 PDT Comment hidden (obsolete)
EWS Watchlist
Comment 35 2018-07-25 13:10:20 PDT Comment hidden (obsolete)
EWS Watchlist
Comment 36 2018-07-25 13:40:39 PDT Comment hidden (obsolete)
EWS Watchlist
Comment 37 2018-07-25 13:40:42 PDT Comment hidden (obsolete)
EWS Watchlist
Comment 38 2018-07-25 13:49:27 PDT Comment hidden (obsolete)
EWS Watchlist
Comment 39 2018-07-25 13:49:29 PDT Comment hidden (obsolete)
Ali Juma
Comment 40 2018-08-08 11:46:37 PDT Comment hidden (obsolete)
EWS Watchlist
Comment 41 2018-08-08 13:45:30 PDT Comment hidden (obsolete)
EWS Watchlist
Comment 42 2018-08-08 13:45:33 PDT Comment hidden (obsolete)
Ali Juma
Comment 43 2018-10-09 14:59:42 PDT Comment hidden (obsolete)
EWS Watchlist
Comment 44 2018-10-09 18:03:02 PDT Comment hidden (obsolete)
EWS Watchlist
Comment 45 2018-10-09 18:03:05 PDT Comment hidden (obsolete)
Ali Juma
Comment 46 2018-11-07 12:45:15 PST
We're now down to a single web platform test failure on trunk (target-in-different-window.html, which covers the case of a single observer with targets in two different browser windows).
Simon Fraser (smfr)
Comment 47 2019-05-30 16:31:46 PDT
Can this be closed now?
Note You need to log in before you can comment on or make changes to this bug.