{"record":{"id":"8eea5bf2378270b2","repo":"grafana/k6","slug":"validating-geo-location-w","errorCode":null,"errorMessage":"validating geo location: %w","messagePattern":"validating geo location: %w","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"internal/js/modules/k6/browser/common/browser_context.go","lineNumber":295,"sourceCode":"func (b *BrowserContext) SetDefaultNavigationTimeout(timeout int64) {\n\tb.logger.Debugf(\"BrowserContext:SetDefaultNavigationTimeout\", \"bctxid:%v timeout:%d\", b.id, timeout)\n\n\tb.timeoutSettings.setDefaultNavigationTimeout(time.Duration(timeout) * time.Millisecond)\n}\n\n// SetDefaultTimeout sets the default maximum timeout in milliseconds.\nfunc (b *BrowserContext) SetDefaultTimeout(timeout int64) {\n\tb.logger.Debugf(\"BrowserContext:SetDefaultTimeout\", \"bctxid:%v timeout:%d\", b.id, timeout)\n\n\tb.timeoutSettings.setDefaultTimeout(time.Duration(timeout) * time.Millisecond)\n}\n\n// SetGeolocation overrides the geo location of the user.\nfunc (b *BrowserContext) SetGeolocation(g *Geolocation) error {\n\tb.logger.Debugf(\"BrowserContext:SetGeolocation\", \"bctxid:%v\", b.id)\n\n\tif err := g.Validate(); err != nil {\n\t\treturn fmt.Errorf(\"validating geo location: %w\", err)\n\t}\n\n\tb.opts.Geolocation = g\n\tfor _, p := range b.browser.getPages() {\n\t\tif err := p.updateGeolocation(); err != nil {\n\t\t\treturn fmt.Errorf(\"updating geo location in target ID %s: %w\", p.targetID, err)\n\t\t}\n\t}\n\n\treturn nil\n}\n\n// SetHTTPCredentials sets username/password credentials to use for HTTP authentication.\n//\n// Deprecated: Create a new BrowserContext with httpCredentials instead.\n// See for details:\n// - https://github.com/microsoft/playwright/issues/2196#issuecomment-627134837\n// - https://github.com/microsoft/playwright/pull/2763","sourceCodeStart":277,"sourceCodeEnd":313,"githubUrl":"https://github.com/grafana/k6/blob/93accf6570dcd306ca5e99cc44c393ee3797761b/internal/js/modules/k6/browser/common/browser_context.go#L277-L313","documentation":"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.","triggerScenarios":"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.","commonSituations":"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'.","solutions":["Check ranges before calling: -90 <= latitude <= 90, -180 <= longitude <= 180, accuracy >= 0","Verify field order — the option is { latitude, longitude }, not [lng, lat]","Use decimal degrees only, never DMS strings","Omit accuracy unless you need it; the default passes validation"],"exampleFix":"// before\nctx.setGeolocation({ latitude: -122.41, longitude: 37.77 }) // latitude out of range\n\n// after\nctx.setGeolocation({ latitude: 37.77, longitude: -122.41, accuracy: 100 })","handlingStrategy":"validation","validationCode":"function validGeo({ latitude, longitude, accuracy = 0 }) {\n  return latitude >= -90 && latitude <= 90\n      && longitude >= -180 && longitude <= 180\n      && accuracy >= 0\n}\nconst geo = { latitude: 37.77, longitude: -122.41 }\nif (validGeo(geo)) ctx.setGeolocation(geo)","typeGuard":"function isValidGeolocation(g) {\n  return typeof g?.latitude === 'number' && typeof g?.longitude === 'number'\n    && g.latitude >= -90 && g.latitude <= 90\n    && g.longitude >= -180 && g.longitude <= 180\n    && (g.accuracy ?? 0) >= 0\n}","tryCatchPattern":null,"preventionTips":["Validate ranges client-side before calling setGeolocation","Remember the field order is { latitude, longitude } — not GeoJSON's [lng, lat]","Use decimal degrees; never pass -1 sentinels for accuracy"],"tags":["validation","geolocation","api-misuse","input"],"backgroundTag":null,"analyzedSha":"93accf6570dcd306ca5e99cc44c393ee3797761b","analyzedAt":"2026-08-15T21:23:27.118Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}