mirror of
https://github.com/puppeteer/puppeteer
synced 2024-06-14 14:02:48 +00:00
chore: make a single visibility check (#12317)
This commit is contained in:
parent
e254f746ee
commit
e35e783a74
@ -1252,17 +1252,13 @@ export abstract class ElementHandle<
|
|||||||
): Promise<string | Buffer> {
|
): Promise<string | Buffer> {
|
||||||
const {scrollIntoView = true, clip} = options;
|
const {scrollIntoView = true, clip} = options;
|
||||||
|
|
||||||
let elementClip = await this.#nonEmptyVisibleBoundingBox();
|
|
||||||
|
|
||||||
const page = this.frame.page();
|
const page = this.frame.page();
|
||||||
|
|
||||||
// Only scroll the element into view if the user wants it.
|
// Only scroll the element into view if the user wants it.
|
||||||
if (scrollIntoView) {
|
if (scrollIntoView) {
|
||||||
await this.scrollIntoViewIfNeeded();
|
await this.scrollIntoViewIfNeeded();
|
||||||
|
|
||||||
// We measure again just in case.
|
|
||||||
elementClip = await this.#nonEmptyVisibleBoundingBox();
|
|
||||||
}
|
}
|
||||||
|
const elementClip = await this.#nonEmptyVisibleBoundingBox();
|
||||||
|
|
||||||
const [pageLeft, pageTop] = await this.evaluate(() => {
|
const [pageLeft, pageTop] = await this.evaluate(() => {
|
||||||
if (!window.visualViewport) {
|
if (!window.visualViewport) {
|
||||||
|
@ -306,14 +306,15 @@ describe('Screenshots', function () {
|
|||||||
|
|
||||||
await page.setContent('<h1>remove this</h1>');
|
await page.setContent('<h1>remove this</h1>');
|
||||||
using elementHandle = (await page.$('h1'))!;
|
using elementHandle = (await page.$('h1'))!;
|
||||||
await page.evaluate((element: HTMLElement) => {
|
await page.evaluate(element => {
|
||||||
return element.remove();
|
return element.remove();
|
||||||
}, elementHandle);
|
}, elementHandle);
|
||||||
const screenshotError = await elementHandle.screenshot().catch(error => {
|
const screenshotError = await elementHandle.screenshot().catch(error => {
|
||||||
return error;
|
return error;
|
||||||
});
|
});
|
||||||
expect(screenshotError.message).toBe(
|
expect(screenshotError).toBeInstanceOf(Error);
|
||||||
'Node is either not visible or not an HTMLElement'
|
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 () => {
|
it('should not hang with zero width/height element', async () => {
|
||||||
|
Loading…
Reference in New Issue
Block a user