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:
parent
301f523956
commit
78941e562c
@ -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();
|
||||
});
|
||||
})();
|
||||
```
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user