Open giri0996 opened 2 months ago
Hi, does it happens on specific pages?
I have mostly seen this behaviour on pdf's with large file sizes around 50 MB, page count approx 750
oh, it's kinda heavy, I've asked, I'm getting same error, but in my case it's pretrty simple page. Page has style tag with CSS inside, weird part is - when I use
@media print {
.non-pdf-link {
display: none !important;
}
.pdf-link {
display: flex !important;
}
.main-content {
zoom: 145%;
}
}
page.pdf(...options) throw Error waiting timeout, even if I increase it still occurs. and in case I've removed media print styles, it works)
I've updated a lib and issue has gone =)
Could you tell me what was updated here for the issue to be gone?
Hi, I have just upgraded the library to the latest version, following the guidelines outlined in the documentation.
I tried with the latest library puppeteer-core == 23.6.1 and chromium Version: 130.0.0, but still receiving the same timeout error
`TimeoutError: Timed out after waiting 30000ms
at /var/task/node_modules/puppeteer-core/lib/cjs/puppeteer/common/util.js:258:19
at /var/task/node_modules/puppeteer-core/lib/cjs/third_party/rxjs/rxjs.js:3986:35
at OperatorSubscriber2._this._next (/var/task/node_modules/puppeteer-core/lib/cjs/third_party/rxjs/rxjs.js:1055:13)
at Subscriber2.next (/var/task/node_modules/puppeteer-core/lib/cjs/third_party/rxjs/rxjs.js:678:16)
at AsyncAction2.
} `
I've faced this issue and got this working with the following versions
"@sparticuz/chromium": "^130.0.0",
"puppeteer-chromium-resolver": "^23.0.0",
"puppeteer-core": "^23.7.1"
Here is my code
"use strict";
const puppeteer = require("puppeteer-core");
const PCR = require("puppeteer-chromium-resolver");
exports.generatePdfFromUrl = async (urlToPrint) => {
try {
const stats = await PCR();
const browser = await puppeteer.launch({
headless: true,
args: ['--no-sandbox'],
executablePath: stats.executablePath,
defaultViewport: { width: 1920, height: 945, deviceScaleFactor: 4 },
});
const options = {
format: 'A4',
headerTemplate: '',
footerTemplate: '',
displayHeaderFooter: false,
margin: {
top: '0px',
bottom: '0px',
},
printBackground: true,
};
const page = await browser.newPage();
await page.setDefaultNavigationTimeout(60000); // Set timeout to 60 seconds
await page.goto(urlToPrint, {
waitUntil: 'networkidle0',
});
// Wait for 5 seconds to ensure all content is loaded
await new Promise(resolve => setTimeout(resolve, 5000));
const buffer = await page.pdf(options);
await page.close();
await browser.close();
return buffer;
} catch (error) {
console.error(error);
throw error;
}
};
Environment
chromium
Version: 126.0.0puppeteer-core
Version: 22.12.1nodejs18.x
|nodejs20.x
Expected Behavior
Generate the pdf and upload to an s3 bucket
Current Behavior
The same code base was working before in nodejs 14.x lambda runtime having chrome-aws-lambda 6.0.0 puppeteer/puppeteer-core 6.0.0.
In Node18.x/20.x lambda runtimegetting a TimeoutError during pdf generation.
Steps to Reproduce
Lambda Memory - 4096 MB, Ephemeral storage - 512 MB, Timeout - 6 MIN
Can some one help me to figure out what is wrong here?