make use of native IntersectionObserver in 3p iframe#6503
make use of native IntersectionObserver in 3p iframe#6503zhouyx merged 7 commits intoampproject:masterfrom
Conversation
| }, { | ||
| threshold: DEFAULT_THRESHOLD, | ||
| }); | ||
| io.observe(window.document.documentElement); |
There was a problem hiding this comment.
window.document.documentElement is the best I can do here. If it does not fill up our 3p iframe, we get different intersection changeEntry between native IO and polyfill IO.
3p/integration.js
Outdated
| }); | ||
| io.observe(window.document.documentElement); | ||
| const unlistener = () => io.unobserve(window.document.documentElement); | ||
| return unlistener; |
ads/_ping_.js
Outdated
| export function _ping_(global, data) { | ||
| global.document.getElementById('c').textContent = data.ping; | ||
|
|
||
| if (!data.nativeIo) { |
There was a problem hiding this comment.
to be explicit, data.nativeIntersectionObserver
test/manual/fakead3p.amp.html
Outdated
| data-url='https://lh3.googleusercontent.com/pSECrJ82R7-AqeBCOEPGPM9iG9OEIQ_QXcbubWIOdkY=w400-h300-no-n' | ||
| data-valid='true' | ||
| data-native-io='true' | ||
| data-unlisten-io='true' |
There was a problem hiding this comment.
nit, maybe pass in a number as seconds?
|
|
||
| if (!data.nativeIntersectionObserver) { | ||
| const nullIO = () => {}; | ||
| nullIO.prototype = null; |
There was a problem hiding this comment.
This is an error, arrow functions do not have prototypes. Also, setting a prototype to null doesn't prevent instances from getting a prototype chain, only Object.create(null) does that.
There was a problem hiding this comment.
hmmm, but it did work though. What should I do to assign the window.IntersectionObserver to null in this case. type-check require it to be a function, and this is my hack to fake native IntersectionObserver 😢
There was a problem hiding this comment.
Use a function declaration instead.
function nullIO() {};
nullIO.prototype = Object.create(null); // Note you'll have to update your prototype check* use native io and disable io for test * return unlisten func * update comment * s * fix type check * add comment * fix type check
…ect#6503)" (ampproject#6685) This reverts commit 7ff2657.
* use native io and disable io for test * return unlisten func * update comment * s * fix type check * add comment * fix type check
…ect#6503)" (ampproject#6685) This reverts commit 7ff2657.
close #5603