{"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/01ffac6f245854c1b8adc6a69857c76a15f90022/internal/js/modules/k6/browser/common/browser_context.go#L277-L313","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","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: {...} })"],"exampleFix":"// before\nctx.setGeolocation({ latitude: 139.69, longitude: 35.68 }); // latitude out of range\n\n// after\nctx.setGeolocation({ latitude: 35.68, longitude: 139.69 }); // Tokyo, valid","handlingStrategy":"validation","validationCode":"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 === undefined || g.accuracy >= 0);\n}\nconst geo = { latitude: 35.68, longitude: 139.69 };\nif (isValidGeolocation(geo)) {\n  ctx.setGeolocation(geo);\n}","typeGuard":"const isGeolocation = (g) =>\n  g != null && typeof g === 'object'\n  && Number.isFinite(g.latitude) && Number.isFinite(g.longitude)\n  && g.latitude >= -90 && g.latitude <= 90\n  && g.longitude >= -180 && g.longitude <= 180;","tryCatchPattern":null,"preventionTips":["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"],"tags":["browser","geolocation","validation","range"],"backgroundTag":"argument-out-of-range","analyzedSha":"01ffac6f245854c1b8adc6a69857c76a15f90022","analyzedAt":"2026-08-18T03:05:52.393Z","contentChangedAt":"2026-08-18T03:05:52.393Z","schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}