Take a screenshot of page using Chrome --headless + cookies/oauth token - google-chrome

I've found, that it's possible to take a page screenshot easily - https://superuser.com/questions/1410641/how-to-take-screenshots-of-a-list-of-urls - by calling:
"C:\Program Files (x86)\Google\Chrome\Application\chrome.exe" --headless --disable-gpu --enable-logging --screenshot="C:\path\to\screenshot.png" http://example.com/
However it's starting new Chrome process, which results that I'm able to take a screenshots of simple pages, but what with pages, with authentication (like Oauth2)?
Can I somehow fore chrome, to use already existing "session" of browser, where I'm logged in to interested page, that I'm about to take a screenshot OR to pass oauth2 token or even cookie, somehow?

Related

chrome headless mode run in batch mode

I am trying to convert a series of html files to pdfs and then send the generated pdf file. However, if i start headless chrome like
...chrome.exe --headless --disable-gpu --print-to-pdf=file01.pdf source01.html
The chrome process exits immediately even though it could take some time before the pdf is generated. Is there a way or flag to instruct chrome.exe to wait for the pdf to be saved before exiting?
p.s.
Is there also a way to see html/js erros on the page?
p.p.s
I have given the simplest example.
What I actually run has
--run-all-compositor-stages-before-draw
--virtual-time-budget=10000 # Need to render some stuff first
--enable-logging

Chrome tries to execute .sh file when displaying github page

Whenever I try to display the github page for a bash (sh) script in my regular profile, Chrome tries to execute the script. If I open the page in an Incognito browser Chrome does not try to execute the script and shows the github page with the bash script.
How can I fix my profile to allow me to open github pages with bash (sh) scripts without using the Incognito browser?
PS. Versions or machines do not seem to be the issue...

Problem with content encoding and connecting with DevTools to chrome headless

I am starting a headless chrome instance like that, e.g.
/opt/google/chrome/chrome --headless --disable-gpu --remote-debugging-port=9222 https://www.chromestatus
and want to connect with DevTools to this instance by entering localhost:9222 into a running browser. However, what I see is just some garbled stuff like this here "��TQo�0~ϯ���$���li51����manri̜8�������m::�...", probably because the server process at localhost:9222 sends the response gzipped, but does not include a content-encoding in the response headers (at least, that's my theory why this happens...)
Any idea how I can fix this? I haven't found any option to control this behavior (e.g. to tell the headless chrome instance to not zip the response data...)
BTW: I see the same whether I enter the url in chrome, chromium or firefox or use wget, and also whether I use chrome (Google Chrome 84.0.4147.105) or chromium doesn't make a difference...

Chrome access/request log

I'm looking for a way to output requests and their response codes from Chrome. Basically I would like what is in the Network tab in developer tools in a log file or accessible from outside of Chrome.
I tried starting Chrome with --enable-logging --v=1 but I cannot find any traces of accessed urls.
Is there a way I can get that logging?

Keep Chrome running in headless mode

I want to use Chrome browser in headless mode to produce images (PNG, JPEG) out of SVG graphic. Code works in normal interactive mode, but I have problems to use it in headless mode.
My main problem is that headless Chrome exits before drawing of HTML page is completed. As I understand, if I start Chrome with following arguments:
chromium --headless http://myserver.org
It exits together with document.onload event. But at this moment not all data fetched from the server (I using XMLHttpRequest) and therefore drawing is not complete.
I found workaround if I start chrome with debugging port enabled like:
chromium --headless --remote-debugging-port=7777 http://myserver.org
But this is not that I want, especially when I do not have privileges to open http ports on the node. Is there possibility to let Chrome running longer with other flags? I check a lot of them, but did not found appropriate one. Or is there any other methods to postpone exit of the headless Chrome?
You could try this answer https://stackoverflow.com/a/46424041/4830701
Copy pasted here for reference
Use the binary /opt/google/chrome/chrome directly not google-chrome which points to bash script /usr/bin/google-chrome.
Taken from comments in
https://developers.google.com/web/updates/2017/04/headless-chrome#screenshots