feat(rpc): handle screenshot path on the client (#3352)
This commit is contained in:
parent
7e2cc77524
commit
69c88d8063
|
|
@ -911,7 +911,6 @@ export type PageReloadResult = {
|
||||||
export type PageScreenshotParams = {
|
export type PageScreenshotParams = {
|
||||||
timeout?: number,
|
timeout?: number,
|
||||||
type?: 'png' | 'jpeg',
|
type?: 'png' | 'jpeg',
|
||||||
path?: string,
|
|
||||||
quality?: number,
|
quality?: number,
|
||||||
omitBackground?: boolean,
|
omitBackground?: boolean,
|
||||||
fullPage?: boolean,
|
fullPage?: boolean,
|
||||||
|
|
@ -925,7 +924,6 @@ export type PageScreenshotParams = {
|
||||||
export type PageScreenshotOptions = {
|
export type PageScreenshotOptions = {
|
||||||
timeout?: number,
|
timeout?: number,
|
||||||
type?: 'png' | 'jpeg',
|
type?: 'png' | 'jpeg',
|
||||||
path?: string,
|
|
||||||
quality?: number,
|
quality?: number,
|
||||||
omitBackground?: boolean,
|
omitBackground?: boolean,
|
||||||
fullPage?: boolean,
|
fullPage?: boolean,
|
||||||
|
|
|
||||||
|
|
@ -422,9 +422,12 @@ export class Page extends ChannelOwner<PageChannel, PageInitializer> {
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
async screenshot(options: PageScreenshotOptions = {}): Promise<Buffer> {
|
async screenshot(options: PageScreenshotOptions & { path?: string } = {}): Promise<Buffer> {
|
||||||
return this._wrapApiCall('page.screenshot', async () => {
|
return this._wrapApiCall('page.screenshot', async () => {
|
||||||
return Buffer.from((await this._channel.screenshot(options)).binary, 'base64');
|
const buffer = Buffer.from((await this._channel.screenshot(options)).binary, 'base64');
|
||||||
|
if (options.path)
|
||||||
|
await fsWriteFileAsync(options.path, buffer);
|
||||||
|
return buffer;
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -541,10 +544,7 @@ export class Page extends ChannelOwner<PageChannel, PageInitializer> {
|
||||||
}
|
}
|
||||||
|
|
||||||
async _pdf(options: PDFOptions = {}): Promise<Buffer> {
|
async _pdf(options: PDFOptions = {}): Promise<Buffer> {
|
||||||
const path = options.path;
|
|
||||||
const transportOptions: PagePdfParams = { ...options } as PagePdfParams;
|
const transportOptions: PagePdfParams = { ...options } as PagePdfParams;
|
||||||
if (path)
|
|
||||||
delete (transportOptions as any).path;
|
|
||||||
if (transportOptions.margin)
|
if (transportOptions.margin)
|
||||||
transportOptions.margin = { ...transportOptions.margin };
|
transportOptions.margin = { ...transportOptions.margin };
|
||||||
if (typeof options.width === 'number')
|
if (typeof options.width === 'number')
|
||||||
|
|
@ -558,8 +558,8 @@ export class Page extends ChannelOwner<PageChannel, PageInitializer> {
|
||||||
}
|
}
|
||||||
const result = await this._channel.pdf(transportOptions);
|
const result = await this._channel.pdf(transportOptions);
|
||||||
const buffer = Buffer.from(result.pdf, 'base64');
|
const buffer = Buffer.from(result.pdf, 'base64');
|
||||||
if (path)
|
if (options.path)
|
||||||
await fsWriteFileAsync(path, buffer);
|
await fsWriteFileAsync(options.path, buffer);
|
||||||
return buffer;
|
return buffer;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -701,7 +701,6 @@ Page:
|
||||||
literals:
|
literals:
|
||||||
- png
|
- png
|
||||||
- jpeg
|
- jpeg
|
||||||
path: string?
|
|
||||||
quality: number?
|
quality: number?
|
||||||
omitBackground: boolean?
|
omitBackground: boolean?
|
||||||
fullPage: boolean?
|
fullPage: boolean?
|
||||||
|
|
|
||||||
|
|
@ -360,7 +360,6 @@ export function createScheme(tChannel: (name: string) => Validator): Scheme {
|
||||||
scheme.PageScreenshotParams = tObject({
|
scheme.PageScreenshotParams = tObject({
|
||||||
timeout: tOptional(tNumber),
|
timeout: tOptional(tNumber),
|
||||||
type: tOptional(tEnum(['png', 'jpeg'])),
|
type: tOptional(tEnum(['png', 'jpeg'])),
|
||||||
path: tOptional(tString),
|
|
||||||
quality: tOptional(tNumber),
|
quality: tOptional(tNumber),
|
||||||
omitBackground: tOptional(tBoolean),
|
omitBackground: tOptional(tBoolean),
|
||||||
fullPage: tOptional(tBoolean),
|
fullPage: tOptional(tBoolean),
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue