mirror of
https://github.com/puppeteer/puppeteer
synced 2024-06-14 14:02:48 +00:00
fix: improve screenshot method types (#9529)
The only drawback of adding overrides is that our documentation generator would generate a page for each overload which might be hard to read/find on the documentation website. Closes #9512 #9385
This commit is contained in:
parent
153d65dd83
commit
6847f8835f
@ -69,7 +69,7 @@ The constructor for this class is marked as internal. Third-party code should no
|
||||
| [hover(this)](./puppeteer.elementhandle.hover.md) | | This method scrolls element into view if needed, and then uses [Page.mouse](./puppeteer.page.mouse.md) to hover over the center of the element. If the element is detached from DOM, the method throws an error. |
|
||||
| [isIntersectingViewport(this, options)](./puppeteer.elementhandle.isintersectingviewport.md) | | Resolves to true if the element is visible in the current viewport. |
|
||||
| [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.md) to take a screenshot of the element. If the element is detached from DOM, the method throws an error. |
|
||||
| [screenshot(this, options)](./puppeteer.elementhandle.screenshot.md) | | This method scrolls element into view if needed, and then uses to take a screenshot of the element. If the element is detached from DOM, the method throws an error. |
|
||||
| [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><select></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. |
|
||||
| [toElement(tagName)](./puppeteer.elementhandle.toelement.md) | | Converts the current handle to the given element type. |
|
||||
|
@ -4,7 +4,7 @@ sidebar_label: ElementHandle.screenshot
|
||||
|
||||
# ElementHandle.screenshot() method
|
||||
|
||||
This method scrolls element into view if needed, and then uses [Page.screenshot()](./puppeteer.page.screenshot.md) to take a screenshot of the element. If the element is detached from DOM, the method throws an error.
|
||||
This method scrolls element into view if needed, and then uses to take a screenshot of the element. If the element is detached from DOM, the method throws an error.
|
||||
|
||||
#### Signature:
|
||||
|
||||
|
@ -126,6 +126,8 @@ page.off('request', logRequest);
|
||||
| [queryObjects(prototypeHandle)](./puppeteer.page.queryobjects.md) | | This method iterates the JavaScript heap and finds all objects with the given prototype. |
|
||||
| [reload(options)](./puppeteer.page.reload.md) | | |
|
||||
| [screenshot(options)](./puppeteer.page.screenshot.md) | | |
|
||||
| [screenshot(options)](./puppeteer.page.screenshot_1.md) | | |
|
||||
| [screenshot(options)](./puppeteer.page.screenshot_2.md) | | |
|
||||
| [select(selector, values)](./puppeteer.page.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><select></code> element matching <code>selector</code>, the method throws an error. |
|
||||
| [setBypassCSP(enabled)](./puppeteer.page.setbypasscsp.md) | | Toggles bypassing page's Content-Security-Policy. |
|
||||
| [setCacheEnabled(enabled)](./puppeteer.page.setcacheenabled.md) | | Toggles ignoring cache for each request based on the enabled state. By default, caching is enabled. |
|
||||
|
@ -8,19 +8,23 @@ sidebar_label: Page.screenshot
|
||||
|
||||
```typescript
|
||||
class Page {
|
||||
screenshot(options?: ScreenshotOptions): Promise<Buffer | string>;
|
||||
screenshot(
|
||||
options: ScreenshotOptions & {
|
||||
encoding: 'base64';
|
||||
}
|
||||
): Promise<string>;
|
||||
}
|
||||
```
|
||||
|
||||
## Parameters
|
||||
|
||||
| Parameter | Type | Description |
|
||||
| --------- | ----------------------------------------------------- | ----------------- |
|
||||
| options | [ScreenshotOptions](./puppeteer.screenshotoptions.md) | <i>(Optional)</i> |
|
||||
| Parameter | Type | Description |
|
||||
| --------- | ----------------------------------------------------------------------------------- | ----------- |
|
||||
| options | [ScreenshotOptions](./puppeteer.screenshotoptions.md) & { encoding: 'base64'; } | |
|
||||
|
||||
**Returns:**
|
||||
|
||||
Promise<Buffer \| string>
|
||||
Promise<string>
|
||||
|
||||
Promise which resolves to buffer or a base64 string (depending on the value of `encoding`) with captured screenshot.
|
||||
|
||||
|
27
docs/api/puppeteer.page.screenshot_1.md
Normal file
27
docs/api/puppeteer.page.screenshot_1.md
Normal file
@ -0,0 +1,27 @@
|
||||
---
|
||||
sidebar_label: Page.screenshot_1
|
||||
---
|
||||
|
||||
# Page.screenshot() method
|
||||
|
||||
#### Signature:
|
||||
|
||||
```typescript
|
||||
class Page {
|
||||
screenshot(
|
||||
options?: ScreenshotOptions & {
|
||||
encoding?: 'binary';
|
||||
}
|
||||
): Promise<Buffer>;
|
||||
}
|
||||
```
|
||||
|
||||
## Parameters
|
||||
|
||||
| Parameter | Type | Description |
|
||||
| --------- | ------------------------------------------------------------------------------------ | ----------------- |
|
||||
| options | [ScreenshotOptions](./puppeteer.screenshotoptions.md) & { encoding?: 'binary'; } | <i>(Optional)</i> |
|
||||
|
||||
**Returns:**
|
||||
|
||||
Promise<Buffer>
|
23
docs/api/puppeteer.page.screenshot_2.md
Normal file
23
docs/api/puppeteer.page.screenshot_2.md
Normal file
@ -0,0 +1,23 @@
|
||||
---
|
||||
sidebar_label: Page.screenshot_2
|
||||
---
|
||||
|
||||
# Page.screenshot() method
|
||||
|
||||
#### Signature:
|
||||
|
||||
```typescript
|
||||
class Page {
|
||||
screenshot(options?: ScreenshotOptions): Promise<Buffer | string>;
|
||||
}
|
||||
```
|
||||
|
||||
## Parameters
|
||||
|
||||
| Parameter | Type | Description |
|
||||
| --------- | ----------------------------------------------------- | ----------------- |
|
||||
| options | [ScreenshotOptions](./puppeteer.screenshotoptions.md) | <i>(Optional)</i> |
|
||||
|
||||
**Returns:**
|
||||
|
||||
Promise<Buffer \| string>
|
@ -2123,6 +2123,12 @@ export class Page extends EventEmitter {
|
||||
* @returns Promise which resolves to buffer or a base64 string (depending on
|
||||
* the value of `encoding`) with captured screenshot.
|
||||
*/
|
||||
screenshot(
|
||||
options: ScreenshotOptions & {encoding: 'base64'}
|
||||
): Promise<string>;
|
||||
screenshot(
|
||||
options?: ScreenshotOptions & {encoding?: 'binary'}
|
||||
): Promise<Buffer>;
|
||||
async screenshot(options?: ScreenshotOptions): Promise<Buffer | string>;
|
||||
async screenshot(): Promise<Buffer | string> {
|
||||
throw new Error('Not implemented');
|
||||
|
@ -1270,6 +1270,12 @@ export class CDPPage extends Page {
|
||||
await this.#frameManager.networkManager.setCacheEnabled(enabled);
|
||||
}
|
||||
|
||||
override screenshot(
|
||||
options: ScreenshotOptions & {encoding: 'base64'}
|
||||
): Promise<string>;
|
||||
override screenshot(
|
||||
options?: ScreenshotOptions & {encoding?: 'binary'}
|
||||
): Promise<Buffer>;
|
||||
override async screenshot(
|
||||
options: ScreenshotOptions = {}
|
||||
): Promise<Buffer | string> {
|
||||
|
Loading…
Reference in New Issue
Block a user