Browser compatibility issue with Puppeteer PDF generation on Heroku Node.js

I’m having trouble with a Puppeteer script for making PDFs on Heroku. It works fine in DuckDuckGo but not in Chrome or Edge. Here’s what’s happening:

  1. The script logs in okay
  2. It goes to the dashboard successfully
  3. When it tries to load the report page, it loses the login info

This means I end up with a blank report in Chrome and Edge, but it’s fine in DuckDuckGo. I’ve been stuck on this for a week. Any ideas?

Here’s a simplified version of what I’m trying to do:

const browser = await puppeteer.launch({ headless: true });
const page = await browser.newPage();

await page.goto('https://myapp.com/login');
await page.type('#username', 'myuser');
await page.type('#password', 'mypass');
await page.click('#login-button');

await page.waitForNavigation();

await page.goto('https://myapp.com/report');
await page.pdf({ path: 'report.pdf' });

await browser.close();

Any suggestions on how to fix this cross-browser issue would be great. Thanks!

I encountered a similar issue with Puppeteer on Heroku. The problem likely stems from session management across different pages. Try implementing a solution using cookies or localStorage to persist the login state. Here’s a potential approach:

  1. After login, capture the session cookies.
  2. Before navigating to the report page, set these cookies.
  3. Use page.evaluate() to store and retrieve session data in localStorage if needed.

This method should maintain the login state across page navigations, resolving the blank report issue in Chrome and Edge. Additionally, ensure your Heroku environment has the necessary dependencies for Puppeteer to function correctly with different browsers.

hey noah, have u tried using a headless chrome instead of the default browser? might solve ur issue. also, check if ur using the latest puppeteer version. sometimes older versions can cause weird browser compatibility stuff. good luck mate!

I’ve dealt with similar Puppeteer headaches on Heroku before. One thing that often gets overlooked is proper error handling and timeouts. Try wrapping your page operations in try/catch blocks and increase your timeout values. Sometimes, network latency on Heroku can cause operations to fail silently.

Also, have you considered using a session storage solution like Redis? It can help maintain state between requests more reliably than relying on browser cookies alone. This approach has saved me countless hours of debugging in production environments.

Lastly, double-check your Heroku configs. Make sure you’re using the latest buildpacks and that all necessary dependencies are properly installed. Sometimes, a simple buildpack update can resolve cross-browser inconsistencies.

Keep at it - Puppeteer issues can be tricky, but they’re usually solvable with some persistence!