grafana/k6 · error

emulating timezone %q: %w

Error message

emulating timezone %q: %w

What it means

FrameSession.emulateTimezone (frame_session.go:213) sends Emulation.setTimezoneOverride with the `timezoneId` browser-context option. Chromium validates the ID against its IANA tz database and rejects unknown names (except the swallowed 'already in effect' case), wrapping the error with the offending timezone. Like locale failures, this aborts page initialization.

Source

Thrown at internal/js/modules/k6/browser/common/frame_session.go:213

func (fs *FrameSession) emulateLocale() error {
	action := emulation.SetLocaleOverride().WithLocale(fs.page.browserCtx.opts.Locale)
	if err := action.Do(cdp.WithExecutor(fs.ctx, fs.session)); err != nil {
		if strings.Contains(err.Error(), "Another locale override is already in effect") {
			return nil
		}
		return fmt.Errorf("emulating locale %q: %w", fs.page.browserCtx.opts.Locale, err)
	}
	return nil
}

func (fs *FrameSession) emulateTimezone() error {
	action := emulation.SetTimezoneOverride(fs.page.browserCtx.opts.TimezoneID)
	if err := action.Do(cdp.WithExecutor(fs.ctx, fs.session)); err != nil {
		if strings.Contains(err.Error(), "Timezone override is already in effect") {
			return nil
		}
		return fmt.Errorf("emulating timezone %q: %w", fs.page.browserCtx.opts.TimezoneID, err)
	}
	return nil
}

func (fs *FrameSession) getNetworkManager() *NetworkManager {
	return fs.networkManager
}

func (fs *FrameSession) initDomains() error {
	actions := []Action{
		// TODO: can we get rid of the following by doing DOM related stuff in JS instead?
		dom.Enable(),
		cdplog.Enable(),
		cdpruntime.Enable(),
		target.SetAutoAttach(true, true).WithFlatten(true),
	}
	for _, action := range actions {
		if err := action.Do(cdp.WithExecutor(fs.ctx, fs.session)); err != nil {

View on GitHub (pinned to 93accf6570)

Solutions

  1. Use a valid IANA timezone ID, e.g. 'America/New_York', 'Europe/Berlin', 'UTC'
  2. Validate the ID in Node before the run: Intl.DateTimeFormat(undefined, { timeZone: id }) throws for unknown IDs
  3. Ensure tzdata is installed in the container running chromium

Example fix

// before
const ctx = browser.newContext({ timezoneId: 'GMT+2' });

// after
const ctx = browser.newContext({ timezoneId: 'Europe/Berlin' });
Defensive patterns

Strategy: validation

Validate before calling

function validTimezone(tz) {
  if (!tz) return tz;
  try {
    new Intl.DateTimeFormat(undefined, { timeZone: tz }); // throws for unknown IANA IDs
    return tz;
  } catch {
    throw new Error(`timezoneId is not a valid IANA ID: ${tz}`);
  }
}
browser.newContext({ timezoneId: validTimezone(cfg.timezoneId) });

Type guard

function isIanaTimezone(v: unknown): v is string {
  if (typeof v !== 'string') return false;
  try { new Intl.DateTimeFormat(undefined, { timeZone: v }); return true; } catch { return false; }
}

Prevention

When it happens

Trigger: browser.newContext({ timezoneId: 'America/Nowhere' }), typos like 'UTC+2' or 'GMT-5' (not IANA IDs), 'Asia/Calcutta'-style outdated names on some builds, or an empty string passed explicitly instead of omitted.

Common situations: Using offsets or Windows timezone names instead of IANA IDs, timezone data missing from minimal container images (tzdata not installed / slim chromium build), or config-driven timezone strings that are never validated.

Related errors


AI-assisted analysis of grafana/k6@93accf6570 (2026-08-15). Data as JSON: /api/errors/c0568f2334b5c777. Report an issue: GitHub.