{"record":{"id":"77d28634cd8468a6","repo":"grafana/k6","slug":"updating-geo-location-in-target-id-s-w","errorCode":null,"errorMessage":"updating geo location in target ID %s: %w","messagePattern":"updating geo location in target ID (.+?): %w","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"internal/js/modules/k6/browser/common/browser_context.go","lineNumber":301,"sourceCode":"// 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\nfunc (b *BrowserContext) SetHTTPCredentials(hc Credentials) error {\n\tb.logger.Warnf(\"setHTTPCredentials\", \"setHTTPCredentials is deprecated.\"+\n\t\t\" Create a new BrowserContext with httpCredentials instead.\")\n\tb.logger.Debugf(\"BrowserContext:SetHTTPCredentials\", \"bctxid:%v\", b.id)\n\n\tb.opts.HTTPCredentials = hc","sourceCodeStart":283,"sourceCodeEnd":319,"githubUrl":"https://github.com/grafana/k6/blob/93accf6570dcd306ca5e99cc44c393ee3797761b/internal/js/modules/k6/browser/common/browser_context.go#L283-L319","documentation":"After context-level validation passes, setGeolocation stores the value and calls page.updateGeolocation() — CDP Emulation.setGeolocationOverride — on every currently open page (browser_context.go:301). If any single page's CDP call fails, you get this error naming that page's target ID, with the page-level error in %w. It means the geolocation itself was valid but applying it to an existing page failed.","triggerScenarios":"One open page crashed or its renderer/session died mid-loop; the connection dropping during the call; a page navigating or closing racing the override; a page closed at the CDP level but not yet removed from the browser's page map.","commonSituations":"Calling setGeolocation after some pages have crashed or been closed; heavy pages under memory pressure; geolocation changes attempted during teardown.","solutions":["Call setGeolocation right after creating pages, before navigation or crashes can occur","Close and recreate crashed pages, then retry setGeolocation","Use the target ID in the message to identify exactly which page failed","Check K6_BROWSER_LOG=debug for the underlying CDP error and address the connection/renderer issue"],"exampleFix":"// before\nconst pages = [ctx.newPage(), ctx.newPage()]\nawait pages[0].close()\nctx.setGeolocation({ latitude: 37.77, longitude: -122.41 }) // may hit a dead page session\n\n// after\nctx.setGeolocation({ latitude: 37.77, longitude: -122.41 }) // set before opening/closing pages\nconst pages = [ctx.newPage(), ctx.newPage()] // new pages inherit it","handlingStrategy":"validation","validationCode":"// set geolocation before opening pages so no per-page replay is needed\nconst ctx = browser.newContext({ geolocation: { latitude: 37.77, longitude: -122.41 } })\nconst page = ctx.newPage() // inherits the override","typeGuard":null,"tryCatchPattern":"try {\n  ctx.setGeolocation(geo)\n} catch (e) {\n  if (/updating geo location in target ID/.test(String(e))) {\n    // the named page's session died; close crashed pages and retry once\n  } else throw e\n}","preventionTips":["Prefer the geolocation option in newContext() over later setGeolocation calls","Call setGeolocation before pages can crash or close","Use the target ID in the error to pinpoint the failing page"],"tags":["cdp","geolocation","pages","connection"],"backgroundTag":null,"analyzedSha":"93accf6570dcd306ca5e99cc44c393ee3797761b","analyzedAt":"2026-08-15T21:23:27.118Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}