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
This commit is contained in:
Paweł Gościcki 2021-09-02 09:26:55 +02:00 committed by GitHub
parent 301f523956
commit 78941e562c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -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();
});
})();
```