fraserxu / electron-pdf

📄 A command line tool to generate PDF from URL, HTML or Markdown files.
MIT License
1.24k stars 136 forks source link

electron-pdf hangs indefinitevily on Linux #243

Open Marco-Sulla opened 5 years ago

Marco-Sulla commented 5 years ago

I tried to run electron-pdf http://fraserxu.me test.pdf, as suggested in the help, but it hangs indefinitively without any message. I tried gooogle.com too.

I also tried the solution in this comment. It works for http://fraserxu.me but not for my html file, that is full of SVGs (maybe this is the problem)?

OS: Lubuntu 18.04.2 (Linux 4.15.0-46-generic #49-Ubuntu SMP Wed Feb 6 09:33:07 UTC 2019 x86_64 x86_64 x86_64 GNU/Linux) Electron Version: 4.0.4

codecounselor commented 5 years ago

please include the exact command you are running. And try prepending DEBUG=electron* which might give you some indication where it is getting stuck. You can also append --browserConfig '{"show":true}' to see the window and do any debugging.

Marco-Sulla commented 5 years ago
DEBUG=electron* electron-pdf /home/marco/Desktop/fraser.html ~/Desktop/fraserxu.pdf
Mon, 08 Apr 2019 19:03:50 GMT electronpdf:debug: checking hung windows-> total windows: 1, hung windows: 0, threshold: 300000
Mon, 08 Apr 2019 19:04:20 GMT electronpdf:debug: checking hung windows-> total windows: 1, hung windows: 0, threshold: 300000
Mon, 08 Apr 2019 19:04:50 GMT electronpdf:debug: checking hung windows-> total windows: 1, hung windows: 0, threshold: 300000

--browserConfig '{"show":true}' gives me a blank page, and dev tools are empty.

Command electron-pdf /home/marco/Desktop/fraser.html ~/Desktop/fraserxu.pdf --browserConfig '{ "webPreferences": { "sandbox" : true } }' succeed.

PS: I retried with the page with SVGs, no problem with --browserConfig '{ "webPreferences": { "sandbox" : true } }'

amaloy commented 5 years ago

I don't know if this is helpful, but I put electron-pdf in a Docker container (https://github.com/amaloy/electron-pdf-docker) and had the same problem. I ended up editing cli.js: https://github.com/amaloy/electron-pdf-docker/blob/master/entrypoint.sh#L4 It removes the 'ipc' bit. Not that I know what my change does, I just know it worked for me. :)

itsrachelfish commented 4 years ago

I'm having the same issue on Debian with a HTML file that contains SVGs.

mikkorantalainen commented 3 years ago

I see total hang, too.

Steps to reproduce:

$ mkdir /tmp/test001 $ cd /tmp/test001 $ npm install electron-pdf $ node_modules/.bin/electron-pdf https://slashdot.org/ out.pdf

The process hangs, no CPU usage nor disk I/O.

System info:

$ lsb_release -d Description: Ubuntu 18.04.5 LTS

$ npm --version 6.14.8

$ apt policy nodejs nodejs: Installed: 12.20.0-1nodesource1 Candidate: 12.20.0-1nodesource1 Version table: *** 12.20.0-1nodesource1 500 500 https://deb.nodesource.com/node_12.x bionic/main amd64 Packages 100 /var/lib/dpkg/status

All real browsers (Chrome, Chromium, Firefox etc) do work so this shouldn't be caused by any missing libraries or unsupported features.

brpaz commented 3 years ago

Same happens to me on Fedora.

I only have this warning:

Fontconfig warning: "/usr/share/fontconfig/conf.avail/05-reset-dirs-sample.conf", line 6: unknown element "reset-dirs"

After that, nothing.

jorismak commented 3 years ago

Same here (Ubuntu 20.04 LTS AFAIK),

Tried with show: true and with adding webPreferences: { "sandbox" : true } to it. DEBUG var is set, SENTRY_DSN is set,

One url is working fine (it's a big 'report', so it takes a while to render. You see electron process taking a lot of CPU for some minutes, then a second electron process starts taking CPU and in the CLI I see a debug JSON object being printed... and then the PDF saves and everything clears up).

But the same url with different parameters (render the same report for another country) is not working, but 'hanging around'. The electron process is taking a lot of CPU, I'm looking at the Xwindow and I see the page being rendered, and the scrollbar growing and growing. But after that, nothing. The CPU usage goes away, the page in the Xwindow turns completely white with only the menu bar showing, and nothing happens.

After a while, the hung-window timeout kicks in and kills the window, but electron still hangs around. Increasing the hung-window timeout just makes this time longer, but no PDF is ever created (not even a 0-byte file). The debug-json object I see printed in a working page also does not appear.

It appears for certain URLs the page renders, but electron-pdf never goes to the 'print as PDF' stage.

mikkorantalainen commented 3 years ago

This problem is probably caused by https://github.com/electron/electron/issues/27605

The only known workaround is not to print anything containing an <iframe> element.

jorismak commented 3 years ago

I discovered that it appears electron is crashing. It shows with a 'trap int3' in the dmesg output.

The same page but rendered chunk by chunk is working fine, so in the end we render it in smaller parts and combine them together with qpdf.

Setting ELECTRONPDF_RENDERER_MAX_MEMORY to any amount smaller than 2gb seems to 'fix' it. I say 'fix' in quotes, because it stops the electron process from crashing. But the render-to-PDF time seems to increase exponentially with it, and we had render times of over 12 minutes.

It seems that, independent of the ELECTRONPDF_RENDERER_MAX_MEMORY setting, electron just crashes when it uses more than 2gb of memory. Restricting it so it doesn't use that much memory fixes the crash, but makes the render times way to long to be practical / usable.