ScreenshotNeo

BlogHow-to

How to Set Timezone and Locale for Playwright Screenshots

Set Playwright’s browser locale and timezone globally, per test, or per context—and keep screenshot comparisons consistent across environments.

By the ScreenshotNeo team4 October 20265 min read

Set locale and timezoneId on the Playwright browser context. In Playwright Test, configure them globally in playwright.config.ts, or use test.use() to override them for a test. With Playwright’s library API, pass them to browser.newContext(). These settings affect the browser context, not the test runner’s timezone.

1. Configure timezone and locale globally

Use global configuration when most tests should render in the same locale and timezone. This TypeScript example can go in a standard Playwright Test configuration file:

import { defineConfig } from '@playwright/test';

export default defineConfig({
  use: {
    locale: 'en-GB',
    timezoneId: 'Europe/Paris',
  },
});

Replace the values with the language-region tag and timezone identifier your scenario needs. For example, a German experience in Berlin can use locale: 'de-DE' and timezoneId: 'Europe/Berlin'.

2. Override settings for a test

When only one test needs different emulation, set the options in that spec with test.use():

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

test.use({
  locale: 'de-DE',
  timezoneId: 'Europe/Berlin',
});

test('renders localized date and time', async ({ page }) => {
  await page.goto('https://example.com');
  await expect(page).toHaveScreenshot('berlin-de.png');
});

The settings apply to tests in the relevant scope. Keep overrides near the tests that require them so the emulated context is easy to identify.

3. Set options with the Playwright library API

If you launch and manage the browser yourself instead of using the Playwright Test runner, provide both options when creating the context:

import { chromium } from 'playwright';

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

await page.goto('https://example.com');
await page.screenshot({ path: 'berlin-de.png', fullPage: true });

await context.close();
await browser.close();

For a standard viewport capture, omit fullPage: true. Playwright also supports capturing a locator when only one element is needed.

4. What locale and timezone change

Option Browser behavior it controls Example
locale navigator.language, the Accept-Language request header, and language-sensitive number and date formatting en-GB
timezoneId The timezone used by the browser context for date and time behavior Europe/Paris

Playwright documents the system timezone as the default when no timezone is configured. Use supported language-region tags and timezone identifiers; Playwright’s API documentation refers to ICU’s supported timezone identifiers. [Playwright emulation guide] [Browser API]

These are independent inputs. Setting a browser context’s timezoneId does not change the timezone used by Node.js or the test runner process. If application output is partly generated by the runner, configure the runner separately when needed. For example, set the TZ environment variable in the process environment used to run the tests, and keep that setting consistent with the intended scenario.

5. Capture and compare screenshots

A screenshot can be captured without an assertion:

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

For a full-page image:

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

For a visual assertion in Playwright Test:

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

test('localized page matches baseline', async ({ page }) => {
  await page.goto('https://example.com');
  await expect(page).toHaveScreenshot('localized-page.png');
});

Locale and timezone can make dates, numbers, and language-sensitive content more representative, but they do not guarantee pixel-identical output. Playwright notes that rendering can vary with the operating system, browser version, settings, hardware, power source, and headless mode. Generate and compare baselines in the same environment where possible. For known dynamic regions, use visual comparison configuration to tolerate expected differences or a custom stylesheet to hide volatile elements. [Visual comparisons] [Screenshots guide]

6. Troubleshooting

Symptom Likely cause What to check
The page still shows a different date or time than expected. The options were set on a different context, or the displayed value was generated outside the browser. Set timezoneId on the context used by the page. If Node or another runner process generates the value, configure that process timezone separately.
The page remains in the wrong language. The browser context has no intended locale, or the application selects language using another mechanism. Set locale on the context and inspect the page’s language-selection behavior. Locale influences navigator.language and Accept-Language, but application-specific settings may also matter.
A timezone identifier is rejected. The identifier is unsupported or misspelled. Use a valid identifier supported by the ICU timezone data used by the runtime. Check spelling and capitalization, such as Europe/Berlin.
A screenshot assertion changes between machines. Locale and timezone match, but another rendering input differs. Align operating system, Playwright/browser version, headless mode, and other environment settings with the baseline environment. Handle known dynamic content explicitly.
The browser looks right but test-side date logic differs. Browser context emulation does not set the test runner timezone. Configure the runner process with TZ when test-side date calculations need the same timezone.

7. Performance, reliability, and cost

Locale and timezone are context configuration, not additional screenshot operations. For reliable comparisons, keep the browser and host environment stable and make the locale, timezone, and runner timezone explicit where each is relevant. The cited Playwright documentation does not provide a specific performance or cost figure for these settings; do not assume they make captures faster or slower by a measurable amount.

Or skip the browser setup

For a one-call website capture, use ScreenshotNeo, a website screenshot API and MCP server for developers. See the API documentation for its options and response details.

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,
)
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 Bun.write('shot.webp', res);

ScreenshotNeo accepts cookie and consent banners like a visitor and removes more than 60 known consent platforms, newsletter popups, and chat widgets before capture; each cleanup step can be turned off. Bot checks, blank pages, failed loads, timeouts, and cache hits are not billed, and response headers report the page verdict and billing status. Its MCP server lets AI agents use take_screenshot, get_page_info, and capture_pdf. The free plan includes 1,000 screenshots a month with no card; paid plans start at $5 for 3,000 screenshots. Every feature is on every plan. Visit ScreenshotNeo or create a free account for 1,000 screenshots a month, with no card required.

FAQ

Does Playwright timezone emulation change the test runner timezone?

No. timezoneId configures the browser context. Set the runner process timezone separately, for example with TZ, if the test process needs it.

Should I set locale and timezone together?

Set both when the scenario needs a particular language and local time behavior. They control different browser inputs, so choose each deliberately.

Will matching these settings make screenshots identical everywhere?

No. Host operating system, browser version, hardware, settings, and headless mode can still change rendering. Keep baseline generation and comparison environments consistent.

Can I use the settings without Playwright Test?

Yes. Pass locale and timezoneId to browser.newContext() when using Playwright’s library API.