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 = {
|
||||
timeout?: number,
|
||||
type?: 'png' | 'jpeg',
|
||||
path?: string,
|
||||
quality?: number,
|
||||
omitBackground?: boolean,
|
||||
fullPage?: boolean,
|
||||
|
|
@ -925,7 +924,6 @@ export type PageScreenshotParams = {
|
|||
export type PageScreenshotOptions = {
|
||||
timeout?: number,
|
||||
type?: 'png' | 'jpeg',
|
||||
path?: string,
|
||||
quality?: number,
|
||||
omitBackground?: 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 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> {
|
||||
const path = options.path;
|
||||
const transportOptions: PagePdfParams = { ...options } as PagePdfParams;
|
||||
if (path)
|
||||
delete (transportOptions as any).path;
|
||||
if (transportOptions.margin)
|
||||
transportOptions.margin = { ...transportOptions.margin };
|
||||
if (typeof options.width === 'number')
|
||||
|
|
@ -558,8 +558,8 @@ export class Page extends ChannelOwner<PageChannel, PageInitializer> {
|
|||
}
|
||||
const result = await this._channel.pdf(transportOptions);
|
||||
const buffer = Buffer.from(result.pdf, 'base64');
|
||||
if (path)
|
||||
await fsWriteFileAsync(path, buffer);
|
||||
if (options.path)
|
||||
await fsWriteFileAsync(options.path, buffer);
|
||||
return buffer;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -701,7 +701,6 @@ Page:
|
|||
literals:
|
||||
- png
|
||||
- jpeg
|
||||
path: string?
|
||||
quality: number?
|
||||
omitBackground: boolean?
|
||||
fullPage: boolean?
|
||||
|
|
|
|||
|
|
@ -360,7 +360,6 @@ export function createScheme(tChannel: (name: string) => Validator): Scheme {
|
|||
scheme.PageScreenshotParams = tObject({
|
||||
timeout: tOptional(tNumber),
|
||||
type: tOptional(tEnum(['png', 'jpeg'])),
|
||||
path: tOptional(tString),
|
||||
quality: tOptional(tNumber),
|
||||
omitBackground: tOptional(tBoolean),
|
||||
fullPage: tOptional(tBoolean),
|
||||
|
|
|
|||
Loading…
Reference in a new issue