ScreenshotNeo

BlogHow-to

How to Capture a Playwright Screenshot with a Specific Locale

Set Playwright’s browser locale before navigation, then capture the page. This guide covers locale configuration, screenshots, troubleshooting, and a browser-free API option.

By the ScreenshotNeo team4 October 20268 min read

Set locale when you create the Playwright browser context, before creating or navigating the page. Then capture the page with page.screenshot(). For example, de-DE emulates German as used in Germany:

const browser = await chromium.launch();
const context = await browser.newContext({ locale: 'de-DE' });
const page = await context.newPage();
await page.goto('https://example.com');
await page.screenshot({ path: 'screenshot.png' });
await browser.close();

Locale emulation affects browser behavior, but it cannot force every site to translate its content. A site may choose language from its URL, saved preferences, account settings, or its own language selector. Check the rendered page to confirm it matches your goal. See the official Playwright emulation guide and Page screenshot API.

1. Capture a screenshot with a locale in a standalone script

Install Playwright and its Chromium browser in your project, then save this as an ES module, such as screenshot.mjs. Replace the locale and URL as needed.

import { chromium } from 'playwright';

const browser = await chromium.launch();
try {
  const context = await browser.newContext({ locale: 'de-DE' });
  const page = await context.newPage();
  await page.goto('https://example.com', { waitUntil: 'load' });
  await page.screenshot({ path: 'screenshot.png' });
} finally {
  await browser.close();
}

Playwright applies context settings to pages created in that context. Configure locale before page creation and navigation so the page sees the emulated browser settings from the start. If you reuse a context, its locale is shared by its pages; create another context for a different locale.

For a reproducible project setup, use the Playwright installation guide. The example above uses the Playwright library directly rather than Playwright Test.

2. Configure locale in Playwright Test

For a test suite, set locale in the Playwright Test configuration’s use options. You can also scope it to a project or an individual test. The official test configuration guide documents these options.

Set a default for the test suite

// playwright.config.js
import { defineConfig } from '@playwright/test';

export default defineConfig({
  use: {
    locale: 'de-DE',
  },
});

Use a locale for one project

// playwright.config.js
import { defineConfig } from '@playwright/test';

export default defineConfig({
  projects: [
    {
      name: 'German locale',
      use: { locale: 'de-DE' },
    },
    {
      name: 'US English locale',
      use: { locale: 'en-US' },
    },
  ],
});

Override locale for one test

import { test, expect } from '@playwright/test';

test.use({ locale: 'de-DE' });

test('renders the localized page', async ({ page }) => {
  await page.goto('https://example.com');
  await page.screenshot({ path: 'german-page.png' });
});

Choose the narrowest scope that fits the test. A global default is convenient when the suite targets one locale; project-level settings make locale variants explicit; per-test configuration is useful for an isolated case.

3. Set timezone separately when needed

Locale and timezone are separate browser settings. A locale can affect language negotiation and formatting conventions; a timezone affects browser date and time behavior. Set timezoneId separately when the screenshot needs both:

const context = await browser.newContext({
  locale: 'de-DE',
  timezoneId: 'Europe/Berlin',
});

Playwright documents timezone emulation in its emulation guide. Browser timezone emulation does not change the test runner’s own timezone. If code running outside the page formats dates, configure that environment separately.

4. Choose screenshot output and dimensions

By default, page.screenshot() captures the viewport. Use options to control the output when you need a full page, a particular image format, or a particular pixel scale. The Page API lists the screenshot options.

Need Option Example
Viewport image Default await page.screenshot({ path: 'view.png' })
Entire scrollable page fullPage: true await page.screenshot({ path: 'full.png', fullPage: true })
JPEG output type: 'jpeg' or a .jpg path await page.screenshot({ path: 'view.jpg', type: 'jpeg', quality: 85 })
WebP output type: 'webp' or a .webp path await page.screenshot({ path: 'view.webp', type: 'webp', quality: 85 })
Device-pixel resolution scale: 'device' await page.screenshot({ path: 'retina.png', scale: 'device' })
CSS-pixel resolution scale: 'css' await page.screenshot({ path: 'css-pixels.png', scale: 'css' })

PNG is the default format. When saving to a path, Playwright can infer image type from its extension. JPEG and WebP support a quality setting; PNG is lossless and does not use that quality option. Device scale can yield a larger image than CSS scale. The screenshot API can also return image bytes when you omit path, which lets your code upload or process the buffer directly.

const imageBytes = await page.screenshot({ fullPage: true });

To capture a region, use the screenshot API’s clip option with a rectangle in page coordinates. For a full-page image, remember that very long pages can create large files and may be slower to capture and store.

5. Verify the site actually rendered the intended locale

Emulating de-DE does not guarantee that every site will display German. Locale may influence the browser’s locale-related behavior, but a site’s language can also depend on its route, application logic, stored preference, or signed-in account.

  1. Choose a locale tag appropriate for the language and region you need, such as de-DE or en-US.
  2. Set it on the context or test configuration before navigation.
  3. Navigate to the page and wait for the content your screenshot needs.
  4. Inspect a visible language-specific string or other expected localized content before saving the image.
  5. If the site has a language selector or locale-specific URL, use that site mechanism as well.

For dynamic pages, waiting for navigation to finish may not be enough: client-side content can appear later. Wait for a meaningful selector or application state, rather than relying on an arbitrary delay when possible.

6. Keep visual screenshots repeatable

Locale correctness and pixel-for-pixel stability are different concerns. Playwright’s visual comparisons guide notes that rendering can vary with the host operating system, browser version, settings, hardware, power source, and headless mode. For visual baselines, capture and compare in a consistent environment.

  • Keep the browser version and operating system consistent between baseline creation and comparison.
  • Keep viewport and device scale settings consistent.
  • Set locale explicitly instead of relying on the machine’s default.
  • Set timezone explicitly if date or time output appears in the page.
  • Wait for fonts, images, and application data that affect the visual result.

7. Troubleshooting

Symptom Likely cause Fix
The screenshot remains in the site’s default language The site chooses language from a URL, saved preference, account, or its own selector. Keep the context locale, and also use the site’s locale route or language control. Verify visible content before capture.
Dates or times still look wrong Locale and timezone are independent, or the displayed date is generated by server-side logic. Set timezoneId as well when appropriate. Check whether the site uses account or server preferences.
A test uses a different locale than expected A project or test-level setting may differ from the global default, or the page was created in another context. Check the effective test configuration and set locale at the scope that owns the test’s page.
Localized text is missing from the image The screenshot was taken before client-side rendering or data loading finished. Wait for a stable, locale-specific selector or application state before capturing.
Image dimensions differ across machines Browser environment, viewport, or device scale differs. Use the same environment and explicit viewport and scale settings for baseline and comparison captures.
Screenshot file is unexpectedly large Full-page capture or device-pixel scale increases image dimensions. Capture only the viewport or use CSS scale; choose JPEG or WebP with an appropriate quality value if lossless output is unnecessary.
Screenshot file is missing The output path may be relative to a different working directory, or capture may have failed before writing. Use a known absolute path while debugging, and ensure the script reaches the screenshot call before closing the browser.

8. Performance, reliability, and cost

A local Playwright capture requires launching and maintaining a browser process, loading the target page, waiting for its content, and writing or processing the image. Reusing a browser for multiple captures can avoid repeated browser startup, while separate contexts let captures use different locales and isolated browser state. Full-page and device-scale screenshots can increase image size and processing time. Network conditions and the target site’s own load behavior also affect completion time.

For repeatable results, handle browser cleanup in a finally block, set locale and other relevant emulation options explicitly, and wait for the actual content needed. Playwright itself is a browser automation library; the costs of running it depend on your runtime and infrastructure. If you need a managed screenshot endpoint instead, ScreenshotNeo offers a one-request capture API. Its billing rules and current plans are described below.

9. Or skip the browser setup

ScreenshotNeo is a website screenshot API and MCP server. Send a GET request with a URL to get an image or PDF. Its clean-shot flow accepts cookie and consent banners like a visitor and removes more than 60 known consent platforms, newsletter popups, and chat widgets; each step can be turned off. Bot checks and CAPTCHAs, blank pages, timeouts, failed loads, and cache hits cost nothing, and the response identifies the page verdict and whether it was billed in headers. An MCP server lets Claude, Cursor, and other MCP clients use take_screenshot, get_page_info, and capture_pdf.

For locale-sensitive pages, use a locale-specific URL or configure the site’s language through its own supported mechanism; a screenshot endpoint does not make a site translate just because you need a particular locale. ScreenshotNeo supports custom headers, cookies, and other capture options. See the ScreenshotNeo API documentation.

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

r = requests.get(
    "https://api.screenshotneo.com/v1/shot",
    params={"access_key": "YOUR_API_KEY", "url": "https://stripe.com"},
    timeout=90,
)
r.raise_for_status()
open("shot.webp", "wb").write(r.content)
const q = new URLSearchParams({
  access_key: 'YOUR_API_KEY',
  url: 'https://stripe.com',
});
const res = await fetch(`https://api.screenshotneo.com/v1/shot?${q}`);
if (!res.ok) throw new Error(`Screenshot request failed: ${res.status}`);
await import('node:fs/promises').then(({ writeFile }) =>
  writeFile('shot.webp', Buffer.from(await res.arrayBuffer()))
);
  • Cookie banners, popups, and chat widgets are removed before the shot.
  • Bot checks, blank pages, and failed loads are never billed.
  • An MCP server lets AI agents take screenshots.
  • 1,000 screenshots a month are free with no card; paid plans start at $5 for 3,000.

Plans include Free (1,000 shots per month), Starter ($5 for 3,000), Growth ($15 for 15,000), Pro ($39 for 60,000), Scale ($99 for 250,000), and Business ($249 for 1,000,000). Yearly billing gives two months free, and every feature is on every plan. Sign up for 1,000 free screenshots a month, with no card required.

10. Frequently asked questions

Does setting locale translate a website?

No. It emulates the browser locale. The website still decides which content to show, often using its URL, application settings, stored preferences, or account state.

Can I use a different locale for each test?

Yes. Configure locale at project scope or for an individual test, or create separate browser contexts in a standalone script.

Does locale set the browser timezone?

No. Set timezoneId separately when the page needs timezone emulation.

What is the simplest way to save a full-page screenshot?

Call await page.screenshot({ path: 'full.png', fullPage: true }) after setting the locale and loading the page.

Why can two screenshots with the same locale differ?

Locale is only one input. Browser and host environment, viewport, page state, and timing can also change rendered pixels.