grafana/k6 · error

validating geo location: %w

Error message

validating geo location: %w

What it means

browserContext.setGeolocation(g) first runs Geolocation.Validate (browser_context.go:295 → browser_context_options.go:74): longitude must be in [-180, 180], latitude in [-90, 90], and accuracy non-negative. Violations return errors like `invalid longitude "999.00": precondition -180 <= LONGITUDE <= 180 failed`, wrapped as 'validating geo location: %w'. Validation happens entirely client-side before any CDP call, so this is always an input error.

Source

Thrown at internal/js/modules/k6/browser/common/browser_context.go:295

func (b *BrowserContext) SetDefaultNavigationTimeout(timeout int64) {
	b.logger.Debugf("BrowserContext:SetDefaultNavigationTimeout", "bctxid:%v timeout:%d", b.id, timeout)

	b.timeoutSettings.setDefaultNavigationTimeout(time.Duration(timeout) * time.Millisecond)
}

// SetDefaultTimeout sets the default maximum timeout in milliseconds.
func (b *BrowserContext) SetDefaultTimeout(timeout int64) {
	b.logger.Debugf("BrowserContext:SetDefaultTimeout", "bctxid:%v timeout:%d", b.id, timeout)

	b.timeoutSettings.setDefaultTimeout(time.Duration(timeout) * time.Millisecond)
}

// SetGeolocation overrides the geo location of the user.
func (b *BrowserContext) SetGeolocation(g *Geolocation) error {
	b.logger.Debugf("BrowserContext:SetGeolocation", "bctxid:%v", b.id)

	if err := g.Validate(); err != nil {
		return fmt.Errorf("validating geo location: %w", err)
	}

	b.opts.Geolocation = g
	for _, p := range b.browser.getPages() {
		if err := p.updateGeolocation(); err != nil {
			return fmt.Errorf("updating geo location in target ID %s: %w", p.targetID, err)
		}
	}

	return nil
}

// SetHTTPCredentials sets username/password credentials to use for HTTP authentication.
//
// Deprecated: Create a new BrowserContext with httpCredentials instead.
// See for details:
// - https://github.com/microsoft/playwright/issues/2196#issuecomment-627134837
// - https://github.com/microsoft/playwright/pull/2763

View on GitHub (pinned to 93accf6570)

Solutions

  1. Check ranges before calling: -90 <= latitude <= 90, -180 <= longitude <= 180, accuracy >= 0
  2. Verify field order — the option is { latitude, longitude }, not [lng, lat]
  3. Use decimal degrees only, never DMS strings
  4. Omit accuracy unless you need it; the default passes validation

Example fix

// before
ctx.setGeolocation({ latitude: -122.41, longitude: 37.77 }) // latitude out of range

// after
ctx.setGeolocation({ latitude: 37.77, longitude: -122.41, accuracy: 100 })
Defensive patterns

Strategy: validation

Validate before calling

function validGeo({ latitude, longitude, accuracy = 0 }) {
  return latitude >= -90 && latitude <= 90
      && longitude >= -180 && longitude <= 180
      && accuracy >= 0
}
const geo = { latitude: 37.77, longitude: -122.41 }
if (validGeo(geo)) ctx.setGeolocation(geo)

Type guard

function isValidGeolocation(g) {
  return typeof g?.latitude === 'number' && typeof g?.longitude === 'number'
    && g.latitude >= -90 && g.latitude <= 90
    && g.longitude >= -180 && g.longitude <= 180
    && (g.accuracy ?? 0) >= 0
}

Prevention

When it happens

Trigger: Latitude/longitude swapped so one lands out of range (e.g. latitude: -122.4); passing degrees-minutes-seconds or radians as if decimal degrees; negative accuracy (including -1 sentinels); NaN from string coordinates.

Common situations: Copying coordinates in lng/lat order from geo APIs that list longitude first; mixing up field order between { latitude, longitude } and GeoJSON's [lng, lat]; passing -1 meaning 'unset'.

Related errors


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