From 22aeff1eac9d22048330a16aa3c41293133911e4 Mon Sep 17 00:00:00 2001 From: Nikolay Vitkov <34244704+Lightning00Blade@users.noreply.github.com> Date: Mon, 30 Oct 2023 11:02:43 +0100 Subject: [PATCH] fix: Type for ElementHandle.screenshot (#11274) --- docs/api/puppeteer.elementhandle.md | 3 ++- .../api/puppeteer.elementhandle.screenshot.md | 16 ++++++------- .../puppeteer.elementhandle.screenshot_1.md | 23 +++++++++++++++++++ .../puppeteer-core/src/api/ElementHandle.ts | 4 ++++ 4 files changed, 37 insertions(+), 9 deletions(-) create mode 100644 docs/api/puppeteer.elementhandle.screenshot_1.md diff --git a/docs/api/puppeteer.elementhandle.md b/docs/api/puppeteer.elementhandle.md index 6b0597b3..88f21f50 100644 --- a/docs/api/puppeteer.elementhandle.md +++ b/docs/api/puppeteer.elementhandle.md @@ -73,7 +73,8 @@ The constructor for this class is marked as internal. Third-party code should no | [isIntersectingViewport(this, options)](./puppeteer.elementhandle.isintersectingviewport.md) | | Resolves to true if the element is visible in the current viewport. If an element is an SVG, we check if the svg owner element is in the viewport instead. See https://crbug.com/963246. | | [isVisible()](./puppeteer.elementhandle.isvisible.md) | | Checks if an element is visible using the same mechanism as [ElementHandle.waitForSelector()](./puppeteer.elementhandle.waitforselector.md). | | [press(key, options)](./puppeteer.elementhandle.press.md) | | Focuses the element, and then uses [Keyboard.down()](./puppeteer.keyboard.down.md) and [Keyboard.up()](./puppeteer.keyboard.up.md). | -| [screenshot(this, options)](./puppeteer.elementhandle.screenshot.md) | | This method scrolls element into view if needed, and then uses [Page.screenshot()](./puppeteer.page.screenshot_1.md) to take a screenshot of the element. If the element is detached from DOM, the method throws an error. | +| [screenshot(options)](./puppeteer.elementhandle.screenshot.md) | | This method scrolls element into view if needed, and then uses [Page.screenshot()](./puppeteer.page.screenshot_1.md) to take a screenshot of the element. If the element is detached from DOM, the method throws an error. | +| [screenshot(options)](./puppeteer.elementhandle.screenshot_1.md) | | | | [scrollIntoView(this)](./puppeteer.elementhandle.scrollintoview.md) | | Scrolls the element into view using either the automation protocol client or by calling element.scrollIntoView. | | [select(values)](./puppeteer.elementhandle.select.md) | | Triggers a change and input event once all the provided options have been selected. If there's no <select> element matching selector, the method throws an error. | | [tap(this)](./puppeteer.elementhandle.tap.md) | | This method scrolls element into view if needed, and then uses [Touchscreen.tap()](./puppeteer.touchscreen.tap.md) to tap in the center of the element. If the element is detached from DOM, the method throws an error. | diff --git a/docs/api/puppeteer.elementhandle.screenshot.md b/docs/api/puppeteer.elementhandle.screenshot.md index c3e529bd..a9d9ab92 100644 --- a/docs/api/puppeteer.elementhandle.screenshot.md +++ b/docs/api/puppeteer.elementhandle.screenshot.md @@ -11,19 +11,19 @@ This method scrolls element into view if needed, and then uses [Page.screenshot( ```typescript class ElementHandle { screenshot( - this: ElementHandle, - options?: Readonly - ): Promise; + options: Readonly & { + encoding: 'base64'; + } + ): Promise; } ``` ## Parameters -| Parameter | Type | Description | -| --------- | ----------------------------------------------------------------------------------- | ------------ | -| this | [ElementHandle](./puppeteer.elementhandle.md)<Element> | | -| options | Readonly<[ElementScreenshotOptions](./puppeteer.elementscreenshotoptions.md)> | _(Optional)_ | +| Parameter | Type | Description | +| --------- | --------------------------------------------------------------------------------------------------- | ----------- | +| options | Readonly<[ScreenshotOptions](./puppeteer.screenshotoptions.md)> & { encoding: 'base64'; } | | **Returns:** -Promise<string \| Buffer> +Promise<string> diff --git a/docs/api/puppeteer.elementhandle.screenshot_1.md b/docs/api/puppeteer.elementhandle.screenshot_1.md new file mode 100644 index 00000000..d93b0f59 --- /dev/null +++ b/docs/api/puppeteer.elementhandle.screenshot_1.md @@ -0,0 +1,23 @@ +--- +sidebar_label: ElementHandle.screenshot_1 +--- + +# ElementHandle.screenshot() method + +#### Signature: + +```typescript +class ElementHandle { + screenshot(options?: Readonly): Promise; +} +``` + +## Parameters + +| Parameter | Type | Description | +| --------- | --------------------------------------------------------------------- | ------------ | +| options | Readonly<[ScreenshotOptions](./puppeteer.screenshotoptions.md)> | _(Optional)_ | + +**Returns:** + +Promise<Buffer> diff --git a/packages/puppeteer-core/src/api/ElementHandle.ts b/packages/puppeteer-core/src/api/ElementHandle.ts index ca4fcd45..71a42eff 100644 --- a/packages/puppeteer-core/src/api/ElementHandle.ts +++ b/packages/puppeteer-core/src/api/ElementHandle.ts @@ -1335,6 +1335,10 @@ export abstract class ElementHandle< * {@link Page.(screenshot:2) } to take a screenshot of the element. * If the element is detached from DOM, the method throws an error. */ + async screenshot( + options: Readonly & {encoding: 'base64'} + ): Promise; + async screenshot(options?: Readonly): Promise; @throwIfDisposed() @ElementHandle.bindIsolatedHandle async screenshot(