grafana/k6 · error
validating geo location
Error message
validating geo location: %w
What it means
SetGeolocation validates the Geolocation struct before touching the browser: longitude must be within [-180, 180], latitude within [-90, 90], and accuracy >= 0 (browser_context_options.go:74-85). This error wraps one of those precondition failures, so it is raised client-side with no CDP call made. The value is stored on the context only after validation passes.
Solutions
- Check the ranges before calling: -90 <= latitude <= 90, -180 <= longitude <= 180, accuracy >= 0
- Verify field order and signs of your coordinates (a common bug is swapping latitude and longitude)
- Clamp or reject bad values at the source (fixture/config validation) rather than in the test
- Prefer setting geolocation at context creation: browser.newContext({ geolocation: {...} })
Example fix
// before
ctx.setGeolocation({ latitude: 139.69, longitude: 35.68 }); // latitude out of range
// after
ctx.setGeolocation({ latitude: 35.68, longitude: 139.69 }); // Tokyo, valid Defensive patterns
Strategy: validation
Validate before calling
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 === undefined || g.accuracy >= 0);
}
const geo = { latitude: 35.68, longitude: 139.69 };
if (isValidGeolocation(geo)) {
ctx.setGeolocation(geo);
} Type guard
const isGeolocation = (g) => g != null && typeof g === 'object' && Number.isFinite(g.latitude) && Number.isFinite(g.longitude) && g.latitude >= -90 && g.latitude <= 90 && g.longitude >= -180 && g.longitude <= 180;
Prevention
- Validate lat/long ranges before calling; remember latitude is the -90..90 one
- Set geolocation via browser.newContext({ geolocation }) to avoid mid-test updates
- Sanitize coordinates loaded from fixtures or config
When it happens
Trigger: browserContext.setGeolocation({ latitude: 200 }) or { longitude: -250 }; negative accuracy like { accuracy: -1 }; transposed coordinates where a longitude such as 139.7 is passed as latitude (valid but wrong) or a latitude > 90 is passed as longitude in swapped fields.
Common situations: Copy-pasted coordinate pairs with lat/long swapped or mistyped signs; geolocation data loaded from fixtures/config with bad values; arithmetic that computes out-of-range values before the call.
Related errors
- cookie name must be set: %#v
- cookie value must be set: %#v
- default browser context can't be closed
- if cookie URL is not provided, both domain and path must be…
- incorrect event , is the only event supported
AI-assisted analysis of grafana/k6@01ffac6f24 (2026-08-18).
Data as JSON: /api/errors/8eea5bf2378270b2.
Report an issue: GitHub.
Appendix: 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/2763View on GitHub (pinned to 01ffac6f24)