w3c / IntersectionObserver

Intersection Observer
https://www.w3.org/TR/intersection-observer/
Other
3.62k stars 526 forks source link

Allow setting a root to be the screen rather than the page viewport #471

Open chrishtr opened 3 years ago

chrishtr commented 3 years ago

Proposal: add an option to measure relative to the screen.

Currently, an IntersectionObserver can observe relative to a specific root element, or if not specified, relative to the implicit root, which is the visual viewport of the browser window.

However, there are cases where it would be better to measure relative to the screen instead. Examples include:

a. Content embedded within a WebView that is itself embedded within a native application. The most common example of this is a native app advertisement delivered via WebView.

Currently, this use case is polyfilled by libraries such as the Open Measurement SDK. However, this polyfill has a few challenges, such as the need to use more CPU than necessary to implement (e.g. via polling loops), needed coordination between script code within the WebView and native code, and difficulties in situations where the WebView is larger than the ad creative and is partially off-screen.

b. A browser window that is partially offscreen. Ad visibility measurements would like to know if an ad is not visible on the screen in these cases.

It is not possible to polyfill this use case.