R
Railway•2y ago
Rogue_Ram

Issues with Puppeteer

I'm using a package that internally uses puppeteer to convert markdown to a pdf, ive tried everything i can think of but i end up getting this error:
Error: Failed to launch the browser process!
[0514/033840.383516:ERROR:zygote_host_impl_linux.cc(100)] Running as root without --no-sandbox is not supported. See https://crbug.com/638180.
TROUBLESHOOTING: https://pptr.dev/troubleshooting
at Interface.onClose (/app/node_modules/@puppeteer/browsers/lib/cjs/launch.js:262:24)
at Interface.emit (node:events:525:35)
at Interface.close (node:readline:590:8)
at Socket.onend (node:readline:280:10)
at Socket.emit (node:events:525:35)
at endReadableNT (node:internal/streams/readable:1358:12)
at processTicksAndRejections (node:internal/process/task_queues:83:21)
Error: Failed to launch the browser process!
[0514/033840.383516:ERROR:zygote_host_impl_linux.cc(100)] Running as root without --no-sandbox is not supported. See https://crbug.com/638180.
TROUBLESHOOTING: https://pptr.dev/troubleshooting
at Interface.onClose (/app/node_modules/@puppeteer/browsers/lib/cjs/launch.js:262:24)
at Interface.emit (node:events:525:35)
at Interface.close (node:readline:590:8)
at Socket.onend (node:readline:280:10)
at Socket.emit (node:events:525:35)
at endReadableNT (node:internal/streams/readable:1358:12)
at processTicksAndRejections (node:internal/process/task_queues:83:21)
Which means the project is being ran as root, but puppeteer doesn't support that. I've also tried specifying in the launch options --no-sandbox:
const pdf = await mdToPdf({
content: markdownText,
pdf_options: {
margin: {
top: "0px"
}
},
launch_options: {
args: ['--no-sandbox', '--disable-setuid-sandbox'],
executablePath: 'chromium-browser'
}
}, { as_buffer: true });
const pdf = await mdToPdf({
content: markdownText,
pdf_options: {
margin: {
top: "0px"
}
},
launch_options: {
args: ['--no-sandbox', '--disable-setuid-sandbox'],
executablePath: 'chromium-browser'
}
}, { as_buffer: true });
Since its working locally im pretty sure the only issue is that the project is ran as root, and i was wondering if it was possible to fix this error? I can't seem to find a good way to convert markdown to a PDF without puppeteer, most packages on npm use it internally.
15 Replies
Percy
Percy•2y ago
Project ID: 6dd7933f-9582-4303-b591-7060ba6cf2f3
Brody
Brody•2y ago
untested, but wouldn't this be the correct syntax?
const pdf = await mdToPdf({
content: markdownText,
config: {
pdf_options: {
margin: {
top: "0px"
}
},
launch_options: {
args: ['--no-sandbox', '--disable-setuid-sandbox'],
executablePath: 'chromium-browser'
}
}

}, { as_buffer: true });
const pdf = await mdToPdf({
content: markdownText,
config: {
pdf_options: {
margin: {
top: "0px"
}
},
launch_options: {
args: ['--no-sandbox', '--disable-setuid-sandbox'],
executablePath: 'chromium-browser'
}
}

}, { as_buffer: true });
Rogue_Ram
Rogue_RamOP•2y ago
Hm, ill try it and see if it changes anything yeah, that didn't change anything. still the same error
Brody
Brody•2y ago
is this the package you are using? https://www.npmjs.com/package/md-to-pdf
Rogue_Ram
Rogue_RamOP•2y ago
yes
Brody
Brody•2y ago
i will do some testing and get back to you
Rogue_Ram
Rogue_RamOP•2y ago
Thanks, I've never seen someone actually go out of their way to help that much before lol
Brody
Brody•2y ago
const pdf = await mdToPdf(
{
content: markdownText,
},
{
pdf_options: {
margin: {
top: "0px",
},
},
launch_options: {
headless: "new",
args: ["--no-sandbox", "--disable-setuid-sandbox"],
},
}
);
const pdf = await mdToPdf(
{
content: markdownText,
},
{
pdf_options: {
margin: {
top: "0px",
},
},
launch_options: {
headless: "new",
args: ["--no-sandbox", "--disable-setuid-sandbox"],
},
}
);
this works for me and just so you know as_buffer is not an option for either md-to-pdf or puppeteer
Rogue_Ram
Rogue_RamOP•2y ago
well the rest of the code sorta uses the buffer to create a stream to pipe to the client (which worked locally when including that) but thats odd I will try this and see if it works, ty for your help
Brody
Brody•2y ago
i searched the md-to-pdf packages repo for that config option
Brody
Brody•2y ago
and the puppeteer launch_options does not have a as_buffer option either
Rogue_Ram
Rogue_RamOP•2y ago
so your saying it just returns it as a buffer by default? eh it seems to work now Tysm for your help ive been working on this project non stop all day and my mind is going crazy lol
Rogue_Ram
Rogue_RamOP•2y ago
mm ok
Brody
Brody•2y ago
no problem 🙂
Want results from more Discord servers?
Add your server