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

This is similar to other browsers that report distinct errors for
'not connected' vs 'not visible' cases.
This commit is contained in:
Dmitry Gozman 2020-06-16 06:13:58 -07:00 committed by GitHub
parent 1bc04a088b
commit 9e7ea3ff7b
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 12 additions and 1 deletions

View file

@ -1 +1 @@
1108
1109

View file

@ -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)