fix(page): page.click should work with disabled javascript (#2907)

Unfortunately, disabling javascript in page prevents any microtasks
to be executed even from puppeteer-originating javascript. As a
result, the IntersectionObserver hack we use to conditionally
scroll into view doesn't work.

To workaround this, we start always scrolling before clicking if
page's javascript is disabled.

Fixes #2898
This commit is contained in:
Andrey Lushnikov
2018-07-18 18:51:18 -07:00
committed by GitHub
parent e4e72c9e81
commit 56368aa07a
3 changed files with 20 additions and 2 deletions

View File

@@ -55,11 +55,16 @@ class ElementHandle extends JSHandle {
}
async _scrollIntoViewIfNeeded() {
const error = await this.executionContext().evaluate(async element => {
const error = await this.executionContext().evaluate(async(element, pageJavascriptEnabled) => {
if (!element.isConnected)
return 'Node is detached from document';
if (element.nodeType !== Node.ELEMENT_NODE)
return 'Node is not of type HTMLElement';
// force-scroll if page's javascript is disabled.
if (!pageJavascriptEnabled) {
element.scrollIntoView({block: 'center', inline: 'center', behavior: 'instant'});
return false;
}
const visibleRatio = await new Promise(resolve => {
const observer = new IntersectionObserver(entries => {
resolve(entries[0].intersectionRatio);
@@ -70,7 +75,7 @@ class ElementHandle extends JSHandle {
if (visibleRatio !== 1.0)
element.scrollIntoView({block: 'center', inline: 'center', behavior: 'instant'});
return false;
}, this);
}, this, this._page._javascriptEnabled);
if (error)
throw new Error(error);
}