diff --git a/packages/puppeteer-core/src/api/ElementHandle.ts b/packages/puppeteer-core/src/api/ElementHandle.ts index 70ce46d0b8e..ede5f10b3bc 100644 --- a/packages/puppeteer-core/src/api/ElementHandle.ts +++ b/packages/puppeteer-core/src/api/ElementHandle.ts @@ -1252,17 +1252,13 @@ export abstract class ElementHandle< ): Promise { 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) { diff --git a/test/src/screenshot.spec.ts b/test/src/screenshot.spec.ts index 9880581217b..d86bcba168f 100644 --- a/test/src/screenshot.spec.ts +++ b/test/src/screenshot.spec.ts @@ -306,14 +306,15 @@ describe('Screenshots', function () { await page.setContent('

remove this

'); 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 () => {