Failed to launch the browser process! Syntax error: ")" unexpected

143 Views Asked by At

i have tried package "puppeteer": "^21.1.1" for html to pdf convertion in node js (egg-scripts) but it gives me this error

Error: Failed to launch the browser process! /home/pi/.cache/puppeteer/chrome/chrome-linux64/chrome: 1: Syntax error: ")" unexpected TROUBLESHOOTING: https://pptr.dev/troubleshooting

at Interface.onClose (/api/node_modules/@puppeteer/browsers/lib/cjs/launch.js:277:24) at Interface.emit (node:events:539:35) at Interface.close (node:readline:586:8) at Socket.onend (node:readline:277:10) at Socket.emit (node:events:539:35) at endReadableNT (node:internal/streams/readable:1345:12) at processTicksAndRejections (node:internal/process/task_queues:83:21)

This is my code

async convertHtmlToPdf(orderId) {
const outputPath = path.join(this.config.baseDir, "app/public", "order_pdf_" + 123 + ".pdf");
console.log(outputPath);
const htmlContent = `
    <html>
      <body>
        <h1>Hello, World!</h1>
        <p>This is a sample HTML content to be converted to PDF.</p>
      </body>
    </html>
  `;
const browser = await puppeteer.launch();
const page = await browser.newPage();
// Set the HTML content of the page
await page.setContent(htmlContent, { waitUntil: 'domcontentloaded' });
// Generate PDF from the page
await page.pdf({ path: outputPath, format: 'A4' });
await browser.close();
}

i need some simple plugin or some simple way to convert html to pdf in node js i ask chatGPT about this error but it is giving me funny answers

0

There are 0 best solutions below