fix: Type for ElementHandle.screenshot (#11274)

This commit is contained in:
Nikolay Vitkov 2023-10-30 11:02:43 +01:00 committed by GitHub
parent bec58dd81a
commit 22aeff1eac
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 37 additions and 9 deletions

View File

@ -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 <code>change</code> and <code>input</code> event once all the provided options have been selected. If there's no <code>&lt;select&gt;</code> element matching <code>selector</code>, 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. |

View File

@ -11,19 +11,19 @@ This method scrolls element into view if needed, and then uses [Page.screenshot(
```typescript
class ElementHandle {
screenshot(
this: ElementHandle<Element>,
options?: Readonly<ElementScreenshotOptions>
): Promise<string | Buffer>;
options: Readonly<ScreenshotOptions> & {
encoding: 'base64';
}
): Promise<string>;
}
```
## Parameters
| Parameter | Type | Description |
| --------- | ----------------------------------------------------------------------------------- | ------------ |
| this | [ElementHandle](./puppeteer.elementhandle.md)&lt;Element&gt; | |
| options | Readonly&lt;[ElementScreenshotOptions](./puppeteer.elementscreenshotoptions.md)&gt; | _(Optional)_ |
| Parameter | Type | Description |
| --------- | --------------------------------------------------------------------------------------------------- | ----------- |
| options | Readonly&lt;[ScreenshotOptions](./puppeteer.screenshotoptions.md)&gt; &amp; { encoding: 'base64'; } | |
**Returns:**
Promise&lt;string \| Buffer&gt;
Promise&lt;string&gt;

View File

@ -0,0 +1,23 @@
---
sidebar_label: ElementHandle.screenshot_1
---
# ElementHandle.screenshot() method
#### Signature:
```typescript
class ElementHandle {
screenshot(options?: Readonly<ScreenshotOptions>): Promise<Buffer>;
}
```
## Parameters
| Parameter | Type | Description |
| --------- | --------------------------------------------------------------------- | ------------ |
| options | Readonly&lt;[ScreenshotOptions](./puppeteer.screenshotoptions.md)&gt; | _(Optional)_ |
**Returns:**
Promise&lt;Buffer&gt;

View File

@ -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<ScreenshotOptions> & {encoding: 'base64'}
): Promise<string>;
async screenshot(options?: Readonly<ScreenshotOptions>): Promise<Buffer>;
@throwIfDisposed()
@ElementHandle.bindIsolatedHandle
async screenshot(