I am using AWS Lambda + Puppeteer + Handlebars to generate PDF at runtime. I am creating the HTML on the fly and need to set cookies in order to render some images in the HTML pages before creating the PDF.
Puppeteer v4.0.0 Node v12.x
I have run into 2 issues:
- page.setCookie() not working
- I have custom fonts to be applied to the PDF - I have copied fonts and placed fonts config in the fonts folder and set FONTCONFIG_PATH env variable to /var/task/fonts (which seemed to work in PhantomJS but not in Chrome headless).
I have tried all possible ways to page.setCookie() but it doesn't seem to be working.
Code:
const page = await browser.newPage();
var pdfCookies = {
"name": "edge-auth", // required
"value": conf["edge-auth"], // required
"domain": ".abc.com",
"path": "/",
"httponly": true,
"secure": true
};
await page.setCookie(pdfCookies);
await page.setContent(data, {waitUntil:'networkidle0'});
I have added a console log for "await page.cookies()" - but I get a blank array [] as output.
Any help will be appreciated.