Today I learned
How do I take a full-page screenshot with headless Chrome from the command line?
· updated #Web development
chrome --headless --screenshot captures only the window, and the CLI has no full-page flag. Get the height from the page itself first.
Write it into <title> once fonts are loaded:
<script>
document.fonts.ready.then(() => { document.title = document.documentElement.scrollHeight })
</script>
Read it with --dump-dom, then shoot at that size:
CH="google-chrome"; PAGE="file://$PWD/page.html"
H=$("$CH" --headless=new --virtual-time-budget=8000 --dump-dom "$PAGE" \
| sed -n 's/.*<title>\([0-9]*\)<\/title>.*/\1/p')
"$CH" --headless=new --hide-scrollbars --virtual-time-budget=8000 \
--force-device-scale-factor=2 --window-size=1600,$H --screenshot=out.png "$PAGE"
--virtual-time-budget waits for web fonts and images, and --window-size is in CSS pixels, so scale 2 gives a 3200 px wide PNG.
I used this for a tall game infographic built as HTML instead of with an image generator: no typos in the text, and a fix costs two commands, not a new generation.