From 78941e562c28c8b54626a3c9dc4cd2e7a92a7074 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Pawe=C5=82=20Go=C5=9Bcicki?= Date: Thu, 2 Sep 2021 09:26:55 +0200 Subject: [PATCH] docs(api): correct `createPDFStream` example (#7538) Prior to this patch, the example results in `browser.close()` being executed before the file is generated/written to disk. One needs to listen for the `end` event on the `ReadableStream` before closing the browser, otherwise an exception is raised: UnhandledPromiseRejectionWarning: Error: Protocol error (IO.read): Target closed --- docs/api.md | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/docs/api.md b/docs/api.md index ea0f0fd5..d8a07e30 100644 --- a/docs/api.md +++ b/docs/api.md @@ -1542,7 +1542,9 @@ const puppeteer = require('puppeteer'); const pdfStream = await page.createPDFStream(); const writeStream = fs.createWriteStream('test.pdf'); pdfStream.pipe(writeStream); - await browser.close(); + pdfStream.on('end', async () => { + await browser.close(); + }); })(); ```