Szpadel / chrome-headless-render-pdf

225 stars 67 forks source link

Stuck at "Chrome port open!" #83

Closed AlexAltea closed 1 year ago

AlexAltea commented 1 year ago

I've been using chrome-headless-render-pdf every month without an issue for the past 5 years... until today.

$ chrome-headless-render-pdf --url http://google.com --pdf test.pdf --chrome-binary 'C:\Program Files\Google\Chrome\Application\chrome.exe'
Using C:\Program Files\Google\Chrome\Application\chrome.exe
Waiting for chrome to became available
Chrome port open!
Chrome port open!
Chrome port open!
Chrome port open!
Chrome port open!
[...]

My current environment:

I've updated to from chrome-headless-render-pdf@v1.9.0 to latest v1.10.0, but same issue exists.

I suspect the issue might be within Chrome itself which updated recently.

AlexAltea commented 1 year ago

Updating to Chrome v110.0.5481.78 (Official Build) (64-bit) still does not fix the issue.

AlexAltea commented 1 year ago

Temporary workaround: Use Microsoft Edge to render documents

$ chrome-headless-render-pdf --url http://google.com --pdf test.pdf --chrome-binary 'C:\Program Files (x86)\Microsoft\Edge\Application\msedge.exe'
Using C:\Program Files (x86)\Microsoft\Edge\Application\msedge.exe
Waiting for chrome to became available
Chrome port open!
Connected to HeadlessEdg/109.0.1518.70, protocol 1.3
Opening http://google.com
Wait for load took 170ms
Wait for js execution took 1ms
Wait for animations took 102ms
Saved test.pdf
fethigurcan commented 1 year ago

Same problem has started yesterday. I also tested on ubuntu beside the windows. same sympthoms.

Edge workaround does not work for me :(

@AlexAltea did you find a solution?

Szpadel commented 1 year ago

I'll try to reproduce this on Monday

AlexAltea commented 1 year ago

@AlexAltea did you find a solution?

No I haven't. Currently my Edge version (which still works) is 109.0.1518.70 (Official build) (64-bit).

However, I'm getting update reminders so I will try to keep my computer/browser running until this issue is fixed. Otherwise my invoicing system will break. 😄

I'll try to reproduce this on Monday

@Szpadel Thank you very much. Your library is really helpful.

fethigurcan commented 1 year ago

@Szpadel Hello, I think that I found the solution.

It seems that CDP can't connect to debug port of chrome without any starter URL. So if you add any URL at spawn time, it will be ok.

you can fix with the code below. I have chosen about:blank as URL.

const commandLineOptions = [ '--headless', --remote-debugging-port=${this.port}, '--disable-gpu', ...this.options.chromeOptions, 'about:blank' ];

@AlexAltea if you want quick fix. just copy the uncompiled index.js from node_molues\chrome-headless-render-pdf\index.js to node_molues\chrome-headless-render-pdf\dist folder. And add ,'about:blank' to commandLineOptions in the file like above.

Note: my fix is just tested under ubuntu.

Szpadel commented 1 year ago

@fethigurcan you could also pass it in chromeOptions :) That way you don't need to alter source code

fethigurcan commented 1 year ago

you are right. it is surely more simple workaround. thanks

the way that I dig the problem came to that solution though :))

Szpadel commented 1 year ago

Just releases 1.11.0 that should resolve that issue, let me know if you still have any issues

timon-michel-scopevisio commented 8 months ago

@Szpadel I'm on mentioned version 1.11.0 and still having this issue. Only on a small subset of hosts, even though they should be configured the same way, which is very interesting. They all use the same chromium version, same OS, same patch level of the OS, i cannot explain why this only happens on some hosts. The hotfix adding --chrome-option=about:blank seems to work though, so it seems as though this fix is maybe not released yet?