grafana/k6 · error
updating geo location in target ID
Error message
updating geo location in target ID %s: %w
What it means
The geolocation passed validation and was stored on the context (b.opts.Geolocation = g), but propagating it to one of the already-open pages failed: each page runs Emulation.setGeolocationOverride on its own session, and the page named by targetID rejected the command. Pages processed before the failing one are already updated; the failing page keeps its old override.
Solutions
- Set geolocation when creating the context — browser.newContext({ geolocation: {...} }) — so it applies before pages exist
- Ensure all pages you expect to update are alive; close and reopen pages rather than reusing stale ones
- Retry the call after the page churn settles if it was a transient teardown race
- Inspect the wrapped error to distinguish a dead session from a dead browser
Example fix
// before
const ctx = browser.newContext();
const page = ctx.newPage();
// ... later, page already closed
ctx.setGeolocation({ latitude: 35.68, longitude: 139.69 }); // fails on dead page
// after
const ctx = browser.newContext({ geolocation: { latitude: 35.68, longitude: 139.69 } });
const page = ctx.newPage(); // page is born with the override Defensive patterns
Strategy: try-catch
Validate before calling
// avoid mid-test propagation entirely: set geolocation at context creation
const ctx = browser.newContext({
geolocation: { latitude: 35.68, longitude: 139.69 },
}); Try / catch
try {
ctx.setGeolocation(geo);
} catch (e) {
if (String(e.message).includes('updating geo location in target ID')) {
// one page's session was dead: close stale pages and retry once
for (const p of ctx.pages()) { try { p.close(); } catch (_) {} }
ctx.setGeolocation(geo);
} else {
throw e;
}
} Prevention
- Prefer the geolocation context option over setGeolocation mid-test
- Ensure all pages in the context are alive before context-wide updates
- Don't change geolocation during teardown
When it happens
Trigger: Calling setGeolocation while some pages in the context are closed or closing (their sessions are gone), their targets crashed, or the browser connection dropped mid-loop.
Common situations: setGeolocation called mid-test while parallel iterations close their pages; geolocation changes in teardown after pages died; long-running tests where a tab crashed earlier.
Related errors
- adding init script to browser context
- clearing permissions
- disposing browser context
- adding web vital init script to new browser context
- adding web vital script to new browser context
AI-assisted analysis of grafana/k6@01ffac6f24 (2026-08-18).
Data as JSON: /api/errors/77d28634cd8468a6.
Report an issue: GitHub.
Appendix: source
Thrown at internal/js/modules/k6/browser/common/browser_context.go:301
// 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
func (b *BrowserContext) SetHTTPCredentials(hc Credentials) error {
b.logger.Warnf("setHTTPCredentials", "setHTTPCredentials is deprecated."+
" Create a new BrowserContext with httpCredentials instead.")
b.logger.Debugf("BrowserContext:SetHTTPCredentials", "bctxid:%v", b.id)
b.opts.HTTPCredentials = hcView on GitHub (pinned to 01ffac6f24)