From 5f24f608194fd4252da7b288461427cabc9dabb3 Mon Sep 17 00:00:00 2001 From: Joel Griffith Date: Mon, 15 Mar 2021 02:05:15 -0700 Subject: [PATCH] fix: make screenshots work in puppeteer-web (#6936) --- src/common/Page.ts | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/src/common/Page.ts b/src/common/Page.ts index e325cdee088..92c39fa660b 100644 --- a/src/common/Page.ts +++ b/src/common/Page.ts @@ -1740,13 +1740,16 @@ export class Page extends EventEmitter { options.encoding === 'base64' ? result.data : Buffer.from(result.data, 'base64'); - if (!isNode && options.path) { - throw new Error( - 'Screenshots can only be written to a file path in a Node environment.' - ); + + if (options.path) { + if (!isNode) { + throw new Error( + 'Screenshots can only be written to a file path in a Node environment.' + ); + } + const fs = await helper.importFSModule(); + await fs.promises.writeFile(options.path, buffer); } - const fs = await helper.importFSModule(); - if (options.path) await fs.promises.writeFile(options.path, buffer); return buffer; function processClip(