diff --git a/lib/ElementHandle.js b/lib/ElementHandle.js index b601cb3dd1c..ab9de81a32e 100644 --- a/lib/ElementHandle.js +++ b/lib/ElementHandle.js @@ -359,18 +359,16 @@ class ElementHandle extends JSHandle { * @returns {!Promise} */ isIntersectingViewport() { - return this.executionContext().evaluate( - node => new Promise(resolve => { - const callback = entries => { - resolve(entries[0].isIntersecting); - observer.disconnect(); - }; - const observer = new IntersectionObserver(callback); - - observer.observe(node); - }), - this - ); + return this.executionContext().evaluate(async element => { + const visibleRatio = await new Promise(resolve => { + const observer = new IntersectionObserver(entries => { + resolve(entries[0].intersectionRatio); + observer.disconnect(); + }); + observer.observe(element); + }); + return visibleRatio > 0; + }, this); } } diff --git a/test/assets/offscreenbuttons.html b/test/assets/offscreenbuttons.html index 27192336ea9..d45e2a41298 100644 --- a/test/assets/offscreenbuttons.html +++ b/test/assets/offscreenbuttons.html @@ -15,6 +15,7 @@ #btn7 { right: -70px; top: 175px; } #btn8 { right: -80px; top: 200px; } #btn9 { right: -90px; top: 225px; } + #btn10 { right: -100px; top: 250px; } @@ -26,6 +27,7 @@ +