Skip to content

Playwright is a framework for Web Testing and Automation. It allows testing Chromium, Firefox and WebKit with a single API.

browser(firefox): Page.scrollIntoViewIfNeeded throws for invisible elements (#2584)

Dmitry Gozman9e7ea3ff7bd3
diff --git a/browser_patches/firefox/BUILD_NUMBER b/browser_patches/firefox/BUILD_NUMBER
index 9707e87684..af6316f1e0 100644
--- a/browser_patches/firefox/BUILD_NUMBER
+++ b/browser_patches/firefox/BUILD_NUMBER
@@ -1 +1 @@
-1108
+1109
diff --git a/browser_patches/firefox/juggler/content/PageAgent.js b/browser_patches/firefox/juggler/content/PageAgent.js
index e5ed8358a5..4c759767f7 100644
--- a/browser_patches/firefox/juggler/content/PageAgent.js
+++ b/browser_patches/firefox/juggler/content/PageAgent.js
@@ -621,6 +621,17 @@ class PageAgent {
const unsafeObject = this._frameData.get(frame).unsafeObject(objectId);
if (!unsafeObject.isConnected)
throw new Error('Node is detached from document');
+ if (!unsafeObject.ownerDocument || !unsafeObject.ownerDocument.defaultView)
+ throw new Error('Node is detached from document');
+ const element = unsafeObject.nodeType === 1 ? unsafeObject : unsafeObject.parentElement;
+ if (!element)
+ throw new Error('Node is detached from document');
+ const style = unsafeObject.ownerDocument.defaultView.getComputedStyle(element);
+ if (!style || style.visibility === 'hidden')
+ throw new Error('Node is not visible');
+ const bounds = element.getBoundingClientRect();
+ if (bounds.width <= 0 || bounds.height <= 0)
+ throw new Error('Node is not visible');
if (!rect)
rect = { x: -1, y: -1, width: -1, height: -1};
if (unsafeObject.scrollRectIntoViewIfNeeded)