When I use Google Chrome or Chromium's headless mode to take a screenshot, it takes only HTML Body.
$ chromium --headless --disable-gpu --screenshot --window-size=1280,1080 https://stackoverflow.com/
I want to take a screenshot with the address bar for my convenience...
Then when I see the picture, I never confuse "Which URL did I take?".
How can I take a screenshot with the address bar when using Chrome/Chromium headless mode?
Chrome headless doesn't have a UI it's only have in-memory rendering done which is then being used to provide screenshot after page is loaded into the buffer.
So there is no way to get it out of headless chrome functionality.
But the is other ways. For example on linux you could use command like (ImageMagick should work under other OS too):
convert screenshot.png -background black -fill white -splice 0x20 -annotate +15+15 'http://test.com' -gravity North -pointsize 30 screenshot2.png
Which adds caption to the image with provided text.
So it's easy to wrap it into a single shell script. Something like:
#/bin/bash
url=$1
google-chrome --headless --disable-gpu --screenshot "$url"
current_time=$(date "+%Y.%m.%d-%H.%M.%S")
new_fileName=screenshot_$current_time.png
convert screenshot.png -background black -fill white -splice 0x20 -annotate +15+15 $url -gravity North -pointsize 30 $new_fileName
And use it as ./take_screenshot.sh http://google.com
Related
I am using the CLI for Google Chrome to save an HTML to PDF. I need tp save the PDF in landscape mode, cannot find the command. I am using this command:
google-chrome --headless --disable-gpu --run-all-compositor-stages-before-draw --print-to-pdf-no-header --Landscape=true --print-to-pdf="MyPdf.pdf" "MyHtml.html"
You can not use Landcape on command line for chrome or derivatives like Edge.
That is intentional as the developer team have certainly up to now, resisted expanding similar command line settings for such usage, their recommendation is you should be using API methods.
You can workaround that by using either #page html or by injected javascript or else the printer needs to define the page output.
2017
We don't intend to provide all the flexibility that DevTools provides through command line options: There are various technical reasons why command line options cannot provide the same flexibility.
It appears that Headless Chrome does parse #page as well to some extent, but behaves differently than the desktop version: If you specify #page {size}, headless seems to change the dimensions of the page box (essentially, the print area), and not the sheet, which always remains US Letter sized. However, it does rotate the sheet if you specify {size: landscape}.
The print options are exposed via the DevTools API only (and not via command line flags), see comments #51 and prior.
2021/2? best option is possibly an enabler like https://github.com/dataverity/chromehtml2pdf#readme
The command to use headless Chrome to print webpage as PDF is chrome --headless --disable-gpu --print-to-pdf https://www.chromestatus.com/. The wkhtmltopdf has a feature --window-status ready_to_print to do so.
I ask this question because when I print this webpage contains MathJax.js, it has an error as follows:
The page source of that webpage has the following lines related to mathjax
<script src="../scripts.js"></script>
<script src="../../MathJax/MathJax.js?config=TeX-AMS_SVG"></script>
I would like to ask if there is an option so that Headless Chrome will wait until the page is fully loaded before printing?
We can use two options to achieve this goal: --run-all-compositor-stages-before-draw and --virtual-time-budget=10000.
google image
Hi, stackoverflow, i am trying to debug a react native app on a Mac and when i open chrome in disabled security mode, the data rendered by google chrome is not normal.
google resultas are not shown, and the design of chrome get messed (the image above)
this is the command : open /Applications/Google\ Chrome.app --args --disable-web-security --user-data-dir
You are probably using Chrome 67.
This problem has been fixed in the last Canary, so you can:
wait for the next Chrome
use an old version (e.g. install Chromium 66)
or you can:
Add the --disable-site-isolation-trials argument to chrome via https://docs.cypress.io/api/plugins/browser-launch-api.html#Usage
Reference: https://github.com/cypress-io/cypress/issues/1951#issuecomment-401579981
I'm trying to print a pdf in ubuntu using chrome headless with this command line :
google-chrome --headless --disable-gpu --print-to-pdf=gen2.pdf file:///home/user/Desktop/invoiceTemplate2.html
The file is generated, but without any text and all other styles are applied.
And when I print the same page HTML with chrome directly, it prints ok.
And I've tried to print the same file HTML on windows with headless chrome and it did print ok with the letters and all.
And when I try to print a HTML file but from the internet like :
instead of : file:///home/user/Desktop/invoiceTemplate2.html
I put : http://www.google.com
it prints OK with headless.
Any help will be apreciated, thx.
I want something like this:
%Program files%\Google\Chrome\chrome.exe
http://example.com --no-controls --box-mode
or even just without the address bar (i.e. with controls).
This picture is close to what I'd like, although it has an address bar.
An alternative would be starting chrome like a popup window.
Thanks.
You can start Chrome in "kiosk" mode from the command line or a shortcut with the --kiosk argument
Example:
"C:\Program Files (x86)\Google\Chrome\Application\chrome.exe --kiosk http://example.com"