mirror of
https://github.com/microsoft/playwright.git
synced 2025-06-26 21:40:17 +00:00
feat(chromium): use Element.checkVisibility in isElementVisible (#16592)
Element.checkVisibility is a new browser API that was shipped in chromium 105: https://bugs.chromium.org/p/chromium/issues/detail?id=1309533 Using checkVisibility accounts for the content-visibility:hidden in the user-agent ShadowRoot of the details element, which means we can remove the usage of the AutoExpandDetailsElementFlag (I am trying to remove the flag in chromium). This behavior is covered by the existing "isVisible and isHidden should work with details" test in locator-convenience.spec.ts.
This commit is contained in:
parent
4cd2176155
commit
ab323122d8
@ -60,8 +60,6 @@ export function isElementVisible(element: Element): boolean {
|
||||
if (!element.ownerDocument || !element.ownerDocument.defaultView)
|
||||
return true;
|
||||
const style = element.ownerDocument.defaultView.getComputedStyle(element);
|
||||
if (!style || style.visibility === 'hidden')
|
||||
return false;
|
||||
if (style.display === 'contents') {
|
||||
// display:contents is not rendered itself, but its child nodes are.
|
||||
for (let child = element.firstChild; child; child = child.nextSibling) {
|
||||
@ -72,6 +70,14 @@ export function isElementVisible(element: Element): boolean {
|
||||
}
|
||||
return false;
|
||||
}
|
||||
// Element.checkVisibility checks for content-visibility and also looks at
|
||||
// styles up the flat tree including user-agent ShadowRoots, such as the
|
||||
// details element for example.
|
||||
// @ts-ignore Typescript doesn't know that checkVisibility exists yet.
|
||||
if (Element.prototype.checkVisibility && !element.checkVisibility({ checkOpacity: false, checkVisibilityCSS: false }))
|
||||
return false;
|
||||
if (!style || style.visibility === 'hidden')
|
||||
return false;
|
||||
const rect = element.getBoundingClientRect();
|
||||
return rect.width > 0 && rect.height > 0;
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user