Skip to content

Commit

Permalink
feat(types): export ScreenshotOptions (#6419)
Browse files Browse the repository at this point in the history
  • Loading branch information
JoelEinbinder committed May 20, 2021
1 parent 8490eb3 commit 447a0c4
Show file tree
Hide file tree
Showing 2 changed files with 67 additions and 64 deletions.
128 changes: 65 additions & 63 deletions types/types.d.ts
Expand Up @@ -2418,69 +2418,7 @@ export interface Page {
* Returns the buffer with the captured screenshot.
* @param options
*/
screenshot(options?: {
/**
* An object which specifies clipping of the resulting image. Should have the following fields:
*/
clip?: {
/**
* x-coordinate of top-left corner of clip area
*/
x: number;

/**
* y-coordinate of top-left corner of clip area
*/
y: number;

/**
* width of clipping area
*/
width: number;

/**
* height of clipping area
*/
height: number;
};

/**
* When true, takes a screenshot of the full scrollable page, instead of the currently visible viewport. Defaults to
* `false`.
*/
fullPage?: boolean;

/**
* Hides default white background and allows capturing screenshots with transparency. Not applicable to `jpeg` images.
* Defaults to `false`.
*/
omitBackground?: boolean;

/**
* The file path to save the image to. The screenshot type will be inferred from file extension. If `path` is a relative
* path, then it is resolved relative to the current working directory. If no path is provided, the image won't be saved to
* the disk.
*/
path?: string;

/**
* The quality of the image, between 0-100. Not applicable to `png` images.
*/
quality?: number;

/**
* Maximum time in milliseconds, defaults to 30 seconds, pass `0` to disable timeout. The default value can be changed by
* using the
* [browserContext.setDefaultTimeout(timeout)](https://playwright.dev/docs/api/class-browsercontext#browsercontextsetdefaulttimeouttimeout)
* or [page.setDefaultTimeout(timeout)](https://playwright.dev/docs/api/class-page#pagesetdefaulttimeouttimeout) methods.
*/
timeout?: number;

/**
* Specify screenshot type, defaults to `png`.
*/
type?: "png"|"jpeg";
}): Promise<Buffer>;
screenshot(options?: PageScreenshotOptions): Promise<Buffer>;

/**
* This method waits for an element matching `selector`, waits for [actionability](https://playwright.dev/docs/actionability) checks, waits until
Expand Down Expand Up @@ -11499,6 +11437,70 @@ interface PageWaitForFunctionOptions {
timeout?: number;
}

export interface PageScreenshotOptions {
/**
* An object which specifies clipping of the resulting image. Should have the following fields:
*/
clip?: {
/**
* x-coordinate of top-left corner of clip area
*/
x: number;

/**
* y-coordinate of top-left corner of clip area
*/
y: number;

/**
* width of clipping area
*/
width: number;

/**
* height of clipping area
*/
height: number;
};

/**
* When true, takes a screenshot of the full scrollable page, instead of the currently visible viewport. Defaults to
* `false`.
*/
fullPage?: boolean;

/**
* Hides default white background and allows capturing screenshots with transparency. Not applicable to `jpeg` images.
* Defaults to `false`.
*/
omitBackground?: boolean;

/**
* The file path to save the image to. The screenshot type will be inferred from file extension. If `path` is a relative
* path, then it is resolved relative to the current working directory. If no path is provided, the image won't be saved to
* the disk.
*/
path?: string;

/**
* The quality of the image, between 0-100. Not applicable to `png` images.
*/
quality?: number;

/**
* Maximum time in milliseconds, defaults to 30 seconds, pass `0` to disable timeout. The default value can be changed by
* using the
* [browserContext.setDefaultTimeout(timeout)](https://playwright.dev/docs/api/class-browsercontext#browsercontextsetdefaulttimeouttimeout)
* or [page.setDefaultTimeout(timeout)](https://playwright.dev/docs/api/class-page#pagesetdefaulttimeouttimeout) methods.
*/
timeout?: number;

/**
* Specify screenshot type, defaults to `png`.
*/
type?: "png"|"jpeg";
}

type Devices = {
"Blackberry PlayBook": DeviceDescriptor;
"Blackberry PlayBook landscape": DeviceDescriptor;
Expand Down
3 changes: 2 additions & 1 deletion utils/generate_types/exported.json
Expand Up @@ -6,5 +6,6 @@
"BrowserNewContextOptions": "BrowserContextOptions",
"BrowserNewContextOptionsViewport": "ViewportSize",
"BrowserNewContextOptionsGeolocation": "Geolocation",
"BrowserNewContextOptionsHttpCredentials": "HTTPCredentials"
"BrowserNewContextOptionsHttpCredentials": "HTTPCredentials",
"PageScreenshotOptions": "PageScreenshotOptions"
}

0 comments on commit 447a0c4

Please sign in to comment.