Skip to content

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:

html
<script>
  document.fonts.ready.then(() => { document.title = document.documentElement.scrollHeight })
</script>

Read it with --dump-dom, then shoot at that size:

bash
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.

Docs: https://developer.chrome.com/docs/chromium/headless

The 30-second version

Share LinkedIn Post on X

Related notes

Newsletter

Occasional notes on engineering, game tech, and new tools — no spam, unsubscribe anytime.

Ravy

Engineering manager, founder, and software developer building web platforms, game systems, real-time services, and automation tools. 15 years of shipped work — currently at Gaijin.net.

Get in Touch

Building an MVP, shipping a game feature, or automating a team workflow? Open source or paid — let's talk.

Contact Me
© 2020-2026 XPLOIT FZE. All trademarks, names and logos belong to their respective copyright holders.