grafana/k6 · error
parsing geo location: %w
Error message
parsing geo location: %w
What it means
browserContext.setGeolocation(geolocation) exports its argument to common.Geolocation - a flat object with numeric latitude, longitude, and optional accuracy fields. A shape Sobek cannot export to that struct (a string, array, non-numeric coordinates, or wrong key names) fails conversion and surfaces wrapped in this error before any CDP traffic.
Source
Thrown at internal/js/modules/k6/browser/browser/browser_context_mapping.go:97
return promise(vu, func() (any, error) {
return bc.Cookies(urls...) //nolint:wrapcheck
})
},
"grantPermissions": func(permissions []string, opts sobek.Value) (*sobek.Promise, error) {
popts, err := exportTo[common.GrantPermissionsOptions](vu.Runtime(), opts)
if err != nil {
return nil, fmt.Errorf("parsing grant permission options: %w", err)
}
return promise(vu, func() (any, error) {
return nil, bc.GrantPermissions(permissions, popts)
}), nil
},
"setDefaultNavigationTimeout": bc.SetDefaultNavigationTimeout,
"setDefaultTimeout": bc.SetDefaultTimeout,
"setGeolocation": func(geolocation sobek.Value) (*sobek.Promise, error) {
gl, err := exportTo[common.Geolocation](vu.Runtime(), geolocation)
if err != nil {
return nil, fmt.Errorf("parsing geo location: %w", err)
}
return promise(vu, func() (any, error) {
return nil, bc.SetGeolocation(&gl)
}), nil
},
"setHTTPCredentials": func(httpCredentials sobek.Value) (*sobek.Promise, error) {
creds, err := exportTo[common.Credentials](rt, httpCredentials)
if err != nil {
return nil, fmt.Errorf("parsing HTTP credentials: %w", err)
}
return promise(vu, func() (any, error) {
return nil, bc.SetHTTPCredentials(creds) //nolint:staticcheck
}), nil
},
"setOffline": func(offline bool) *sobek.Promise {
return promise(vu, func() (any, error) {
return nil, bc.SetOffline(offline) //nolint:wrapcheck
})View on GitHub (pinned to 93accf6570)
Solutions
- Use the exact keys with numbers: setGeolocation({ latitude: 48.8584, longitude: 2.2945 })
- Include accuracy only as a number if needed: { latitude, longitude, accuracy: 100 }
- Omit the call entirely to keep the browser default geolocation
Example fix
// before: abbreviated keys -> export fails
await context.setGeolocation({ lat: 48.85, lng: 2.29 });
// after: exact field names with numeric values
await context.setGeolocation({ latitude: 48.8584, longitude: 2.2945 }); Defensive patterns
Strategy: type-guard
Validate before calling
const geo = { latitude: 48.8584, longitude: 2.2945 };
const ok = [geo.latitude, geo.longitude].every((n) => typeof n === 'number' && Number.isFinite(n));
if (!ok) throw new TypeError('geolocation requires numeric latitude/longitude');
await context.setGeolocation(geo); Type guard
function isGeolocation(v) {
return (
typeof v === 'object' &&
v !== null &&
!Array.isArray(v) &&
typeof v.latitude === 'number' &&
typeof v.longitude === 'number' &&
(v.accuracy === undefined || typeof v.accuracy === 'number')
);
} Try / catch
try {
await context.setGeolocation(geo);
} catch (e) {
if (String(e).includes('parsing geo location')) {
console.warn('invalid geolocation shape - skipping');
} else throw e;
} Prevention
- Use full key names latitude/longitude (not lat/lng) with plain numbers
- Keep geolocation objects in one typed constant instead of inline literals at call sites
When it happens
Trigger: setGeolocation('Paris'); setGeolocation(48.85); setGeolocation({ lat: 48.85, lng: 2.29 }) (wrong keys - the struct wants latitude/longitude); nested coordinate objects.
Common situations: Using abbreviated lat/lng key names from other geolocation APIs; passing a coordinates array from a mapping library; copy-pasting Playwright snippets with extra properties.
Related errors
- parsing grant permission options: %w
- parsing HTTP credentials: %w
- parsing wait for event options: %w
- parsing browser.newContext options: %w
- parsing browser.newPage options: %w
AI-assisted analysis of grafana/k6@93accf6570 (2026-08-15).
Data as JSON: /api/errors/cf9c2190d5342040.
Report an issue: GitHub.