Skip to content

Commit

Permalink
docs(api): correct createPDFStream example (#7538)
Browse files Browse the repository at this point in the history
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
  • Loading branch information
pjg committed Sep 2, 2021
1 parent 301f523 commit 78941e5
Showing 1 changed file with 3 additions and 1 deletion.
4 changes: 3 additions & 1 deletion docs/api.md
Expand Up @@ -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();
});
})();
```

Expand Down

0 comments on commit 78941e5

Please sign in to comment.