Goal
browser-based-export
is a wrapper on top of Puppeteer's export to PDF feature.
It can handle authentication by injecting cookies or Web Storage items into Headless Chromium.
It also generates better looking PDF than Puppeteer by resizing the browser page to the paper format before triggering the PDF export.
The library is also available as a server and an AWS Lambda.
Export isolation
Every export happens in an isolated incognito Chromium context.
It means that the cookies, Web Storage items or any sensitive information will not be shared across exports.
Even if they are launched in parallel.
Usage
Example
const {inBrowser} = require('browser-based-export');
inBrowser({
action: ({exportPdf}) =>
exportPdf({
payload: {
url: 'https://example.com',
},
timeoutInSeconds: 10,
}).then(pdfBuffer => {
}),
});
Take a look at:
Troubleshooting
This package is using the debug utility.
Set the DEBUG
environment variable to browser-based-export:*
to see the debug messages.
If that's not enough, you can follow the Puppeteer debugging tips.