chore: make a single visibility check (#12317)

This commit is contained in:
Nikolay Vitkov 2024-04-24 15:13:09 +02:00 committed by GitHub
parent e254f746ee
commit e35e783a74
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 5 additions and 8 deletions

View File

@ -1252,17 +1252,13 @@ export abstract class ElementHandle<
): Promise<string | Buffer> {
const {scrollIntoView = true, clip} = options;
let elementClip = await this.#nonEmptyVisibleBoundingBox();
const page = this.frame.page();
// Only scroll the element into view if the user wants it.
if (scrollIntoView) {
await this.scrollIntoViewIfNeeded();
// We measure again just in case.
elementClip = await this.#nonEmptyVisibleBoundingBox();
}
const elementClip = await this.#nonEmptyVisibleBoundingBox();
const [pageLeft, pageTop] = await this.evaluate(() => {
if (!window.visualViewport) {

View File

@ -306,14 +306,15 @@ describe('Screenshots', function () {
await page.setContent('<h1>remove this</h1>');
using elementHandle = (await page.$('h1'))!;
await page.evaluate((element: HTMLElement) => {
await page.evaluate(element => {
return element.remove();
}, elementHandle);
const screenshotError = await elementHandle.screenshot().catch(error => {
return error;
});
expect(screenshotError.message).toBe(
'Node is either not visible or not an HTMLElement'
expect(screenshotError).toBeInstanceOf(Error);
expect(screenshotError.message).toMatch(
/Node is either not visible or not an HTMLElement|Node is detached from document/
);
});
it('should not hang with zero width/height element', async () => {