How to Capture Hindi Web Pages with Chrome Headless
In this article
Rendering Hindi text correctly in headless Chrome screenshots can be tricky due to font shaping and complex script rendering. This guide walks you through the exact steps to capture accurate, readable Hindi web pages using Chrome's headless mode, including handling Devanagari script and ensuring proper font support.
What You'll Need
- Google Chrome or Chromium browser installed (version 60+ for headless mode)
- Command-line terminal (Command Prompt, PowerShell, or bash)
- Basic familiarity with running commands
- Optional: A Hindi font installed on your system (like Noto Sans Devanagari) for better rendering
Step-by-Step
- Open your terminal – On Windows, press Win + R, type
cmd, and press Enter. On macOS/Linux, open Terminal from Applications or via Ctrl+Alt+T. - Navigate to your Chrome installation directory – Typically:
- Windows:
C:\Program Files\Google\Chrome\Application\ - macOS:
/Applications/Google Chrome.app/Contents/MacOS/ - Linux:
/usr/bin/google-chrome(orchromium)
- Windows:
- Run the basic headless screenshot command – Use the following syntax:
Replacechrome --headless --disable-gpu --screenshot="output.png" --window-size=1280,720 "https://example.com"chromewith the full path if needed. This captures the page at 1280x720 resolution. - Add the
--force-device-scale-factorflag for higher quality – To get a sharper image, especially for text, add--force-device-scale-factor=2(for 2x resolution) or=3for 3x. Example:chrome --headless --disable-gpu --force-device-scale-factor=2 --screenshot="hindi.png" --window-size=1280,720 "https://hi.wikipedia.org" - Ensure Hindi fonts are available – If the page uses Devanagari, headless Chrome needs a font that supports it. Install a font like Noto Sans Devanagari (available from Google Fonts) on your system. On Linux, you may need to install
fonts-noto-coreorfonts-devavia your package manager. - Use the
--virtual-time-budgetflag for dynamic content – If the page loads Hindi text via JavaScript, wait for it to render by adding--virtual-time-budget=5000(5 seconds). Example:chrome --headless --disable-gpu --virtual-time-budget=5000 --screenshot="hindi-dynamic.png" "https://example.com/hindi-page" - Capture a full-page screenshot – To capture the entire page, use
--screenshotwith--window-sizeset to a tall height (e.g.,1280,5000) or use the newer--headless=newmode which supports full-page capture via--screenshot --full-page(requires Chrome 112+). Example:chrome --headless=new --screenshot="full-hindi.png" --full-page --window-size=1280,0 "https://hi.wikipedia.org" - Verify the output – Open the PNG file and check that Hindi characters appear correctly (no boxes or missing glyphs). If text is missing, proceed to troubleshooting.
Common Mistakes
- Forgetting the
--disable-gpuflag – On some systems, GPU issues cause blank screenshots. Always include it. - Using an old Chrome version – Headless mode has improved significantly. Update to the latest stable version.
- Not specifying the full path to Chrome – If Chrome isn't in your PATH, the command fails. Use the full path.
- Overlooking font installation – Without a Devanagari font, Chrome falls back to a default that may not render Hindi correctly.
- Setting window size too small – A small viewport can cause text to wrap or be cut off. Use at least 1280px width.
Tips
- Use
--hide-scrollbarsto avoid scrollbars in the screenshot. - For consistent results, use the same Chrome version across your team or CI pipeline.
- If you need to capture multiple pages, write a simple loop in bash or PowerShell to iterate over URLs.
- For Hindi pages that use web fonts (like Google Fonts), ensure the page's CSS loads them; headless Chrome will download them automatically if internet is available.
- Test with a simple Hindi page first (e.g.,
https://hi.wikipedia.org) to confirm your setup works.
Troubleshooting
- Blank or white screenshot – Add
--no-sandbox(especially on Linux) and--disable-dev-shm-usageif running in a container. Also try--headless=new. - Hindi text shows as boxes (tofu) – Install a Devanagari font (e.g.,
sudo apt install fonts-noto-coreon Ubuntu). Also check if the page uses a specific font that isn't loading. - Text is cut off or misaligned – Increase the window height or use full-page capture. Also ensure
--force-device-scale-factoris set appropriately. - JavaScript-rendered content missing – Use
--virtual-time-budgetto allow time for scripts to run. Increase the value if content loads slowly. - Command not found – On macOS, the binary is inside the .app bundle; use the full path. On Windows, ensure you're in the correct directory or use the full path.
- Chrome crashes on startup – Try
--no-sandboxand--disable-gpu. If you're on a server, you may need to usexvfb-runon Linux.
Frequently Asked Questions
Can I capture a Hindi page as PDF instead of PNG?
Yes, replace --screenshot with --print-to-pdf. For example: chrome --headless --disable-gpu --print-to-pdf="hindi.pdf" "https://hi.wikipedia.org". The same font rules apply.
Does headless Chrome support Devanagari conjuncts correctly?
Yes, as long as a proper Devanagari font is installed and used. Chrome uses HarfBuzz for text shaping, which handles complex scripts like Devanagari correctly.
Why does my screenshot show Latin text instead of Hindi?
This usually happens if the page's language is set to English or if the font doesn't support Devanagari. Check the page's lang attribute and ensure the font supports the script.
Can I use headless Chrome in a Docker container?
Yes, but you need to install fonts and dependencies. Use an image like zenika/alpine-chrome or install Chrome and fonts manually. Add --no-sandbox and --disable-dev-shm-usage for containers.
How do I capture only a specific element of the page?
Headless Chrome's command-line doesn't support element capture directly. You'd need to use Puppeteer or Selenium to interact with the DOM and capture a specific element.
Is there a way to capture Hindi pages without installing fonts?
You can rely on web fonts loaded from the page itself, but if the page doesn't use web fonts, you must have a system font. There's no workaround for missing fonts.