grafana/k6 · error

updating geo location in target ID %s: %w

Error message

updating geo location in target ID %s: %w

What it means

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.

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 = hc

View on GitHub (pinned to 93accf6570)

Solutions

  1. Call setGeolocation right after creating pages, before navigation or crashes can occur
  2. Close and recreate crashed pages, then retry setGeolocation
  3. Use the target ID in the message to identify exactly which page failed
  4. Check K6_BROWSER_LOG=debug for the underlying CDP error and address the connection/renderer issue

Example fix

// before
const pages = [ctx.newPage(), ctx.newPage()]
await pages[0].close()
ctx.setGeolocation({ latitude: 37.77, longitude: -122.41 }) // may hit a dead page session

// after
ctx.setGeolocation({ latitude: 37.77, longitude: -122.41 }) // set before opening/closing pages
const pages = [ctx.newPage(), ctx.newPage()] // new pages inherit it
Defensive patterns

Strategy: validation

Validate before calling

// set geolocation before opening pages so no per-page replay is needed
const ctx = browser.newContext({ geolocation: { latitude: 37.77, longitude: -122.41 } })
const page = ctx.newPage() // inherits the override

Try / catch

try {
  ctx.setGeolocation(geo)
} catch (e) {
  if (/updating geo location in target ID/.test(String(e))) {
    // the named page's session died; close crashed pages and retry once
  } else throw e
}

Prevention

When it happens

Trigger: 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.

Common situations: Calling setGeolocation after some pages have crashed or been closed; heavy pages under memory pressure; geolocation changes attempted during teardown.

Related errors


AI-assisted analysis of grafana/k6@93accf6570 (2026-08-15). Data as JSON: /api/errors/77d28634cd8468a6. Report an issue: GitHub.