ScreenshotNeo

BlogHow-to

How to Take a Playwright Screenshot of a Hindi Government Website

Capture a Hindi government page with Playwright, choose viewport, full-page, or element screenshots, and troubleshoot rendering and navigation issues.

By the ScreenshotNeo team4 October 20266 min read

Use Playwright to open the portal’s Hindi page, wait for it to load, then call page.screenshot(). Use fullPage: true to capture the whole scrollable page; omit it for the visible viewport. Replace the example URL below with the portal’s published Hindi URL or navigate to Hindi using its own language control. The example host is illustrative, not a verified government website.

const { chromium } = require('playwright');

(async () => {
  const browser = await chromium.launch();
  try {
    const page = await browser.newPage({ viewport: { width: 1440, height: 1000 } });
    await page.goto('https://example.gov.in/', { waitUntil: 'domcontentloaded', timeout: 60000 });
    await page.screenshot({ path: 'hindi-government-page.png', fullPage: true });
  } finally {
    await browser.close();
  }
})();

Install Playwright and its browser for your runtime by following the official installation guide. The screenshot API and options are documented in the Page API and Screenshots guide.

1. Choose the right Hindi page

The screenshot call does not choose a language. Start from the portal’s published Hindi URL, or use the site’s language control and confirm that the Hindi page has loaded before capturing. Government portals may use different routes, redirects, or session state; there is no universal Hindi URL parameter or selector.

If the page requires a session or consent choice, handle it according to the portal’s normal flow and applicable access rules. Do not assume a particular login, banner, or language-switch behavior.

2. Capture the page with Playwright

For a quick viewport capture, omit fullPage. For a page record that includes below-the-fold content, set fullPage: true. Playwright can also save screenshot bytes to a buffer for processing or sending to another tool.

Viewport screenshot

await page.screenshot({ path: 'viewport.png' });

Full-page screenshot

await page.screenshot({ path: 'full-page.png', fullPage: true });

Capture one element

Use a locator when you need a form, notice, table, or another specific component rather than the whole page. Choose a selector that exists on the actual portal; this example selector is only illustrative.

const notice = page.locator('main');
await notice.screenshot({ path: 'main-content.png' });

Capture bytes instead of writing a file

const imageBytes = await page.screenshot({ fullPage: true, type: 'png' });
// Pass imageBytes to your storage or image-processing code.

3. Set capture options deliberately

Need Option or approach Notes
Visible screen only Default page.screenshot() Captures the current viewport.
Entire scrollable page fullPage: true Useful when content below the fold matters; a very tall page creates a larger image.
One component locator.screenshot() Use a locator for the target element.
JPEG or WebP type: 'jpeg' or type: 'webp' Choose a format supported by the Playwright version in your project; JPEG supports a quality setting.
Higher pixel density scale: 'css' or scale: 'device' Select the desired scale for your output and version. Device scale can produce more pixels.
Image for code to process Omit path and use the returned buffer Useful for upload or in-memory processing.

Other screenshot options include output path, image type, JPEG quality, clipping, animations, caret behavior, and transparency. Check the API documentation for the Playwright version you run, since option support can vary. For a reproducible record, keep the browser version, viewport, scale, URL, and chosen options consistent.

4. Verify Devanagari text and page layout

Open the resulting image and inspect the actual Hindi text, glyph shapes, line wrapping, and page sections. Playwright’s screenshot operation captures pixels; it does not establish that the portal served Hindi or that every font rendered correctly. If glyphs are missing or layout is unexpected, diagnose that specific page and browser environment rather than adding an assumed font or URL parameter.

A screenshot records appearance, not page structure or accessible text. For understanding page structure or reading content programmatically, Playwright documents accessibility snapshots as a separate tool: Screenshots | Playwright MCP.

5. Troubleshooting

Symptom Likely cause What to do
Navigation times out Slow response, redirect, or page activity exceeding the timeout Check that the URL is correct and reachable in the same environment. Set an explicit, reasonable timeout; choose a navigation wait condition appropriate for the page.
Screenshot is blank or incomplete Capture happened before the relevant content appeared, or the page failed to load Inspect the page after navigation. Wait for a known, page-specific selector or a short delay only when needed, then capture again.
Hindi characters appear missing or wrong Page content, font loading, or browser rendering differs from expectation Verify the portal is on its Hindi route and inspect the rendered page in the same browser environment. Investigate the specific font or site behavior; no universal fix is established.
Only the top portion is present Default viewport capture was used Set fullPage: true, or scroll and capture a specific region if that better fits the task.
Element locator finds nothing Example selector does not match the portal, or target has not appeared Inspect the page DOM and use a selector for the actual element. Wait for that locator before calling its screenshot method.
Browser launch fails Playwright browser is missing or runtime dependencies are not set up Follow the official installation instructions for the project’s runtime and install the matching browser.
Full-page image is unexpectedly large The document is very tall or device scale is high Capture a viewport or target element, or select an appropriate scale and output format.

6. Reliability, performance, and cost

For reliable captures, use an explicit viewport and timeout, close the browser in a finally block, and save the URL and capture settings alongside the image when you need an audit trail. Wait for a page-specific readiness signal when content is dynamic; avoid assuming one fixed delay works for every portal.

Full-page captures and high device scale can increase image dimensions, memory use, and processing time. Viewport or locator captures limit the scope. The dossier provides no benchmark for government pages or capture duration, so measure against the portal and runtime you actually use. Playwright itself is browser automation software; your infrastructure and browser execution determine its operating cost.

Or skip the browser setup

ScreenshotNeo is a website screenshot API and MCP server. One GET request returns an image or PDF, and the same API accepts parameter names used by other screenshot APIs. See the ScreenshotNeo documentation.

curl -G "https://api.screenshotneo.com/v1/shot" -d access_key=YOUR_API_KEY --data-urlencode url=https://example.gov.in/ -o shot.webp
import requests

r = requests.get(
    "https://api.screenshotneo.com/v1/shot",
    params={"access_key": "YOUR_API_KEY", "url": "https://example.gov.in/"},
    timeout=90,
)
open("shot.webp", "wb").write(r.content)
const q = new URLSearchParams({
  access_key: 'YOUR_API_KEY',
  url: 'https://example.gov.in/'
});
const res = await fetch(`https://api.screenshotneo.com/v1/shot?${q}`);
if (!res.ok) throw new Error(`Screenshot request failed: ${res.status}`);
await require('node:fs/promises').writeFile('shot.webp', Buffer.from(await res.arrayBuffer()));

Replace the example address with the Hindi page URL. Configure viewport, full-page capture, output format, waits, and other options using the documented API parameters. ScreenshotNeo accepts cookie banners before capture and removes more than 60 known consent platforms, newsletter popups, and chat widgets; each step can be turned off. Bot checks, blank pages, timeouts, failed loads, and cache hits cost nothing, and response headers identify the page verdict and billing status. Its MCP server provides take_screenshot, get_page_info, and capture_pdf tools for AI agents. The free plan includes 1,000 screenshots per month with no card; paid plans start at $5 for 3,000 screenshots.

Sign up for 1,000 free screenshots a month, with no card required.

FAQ

Does Playwright automatically switch a government site to Hindi?

No. Navigate to the portal’s Hindi URL or use its own language control, then verify the rendered page.

Should I use a screenshot to extract Hindi text?

A screenshot is an image of the page’s appearance. Use page content or accessibility information when you need text or structure.

Can I capture just a form or notice?

Yes. Locate the element and call its screenshot method.