grafana/k6 · error
invalid longitude "%.2f": precondition -180 <= LONGITUDE <=
Error message
invalid longitude "%.2f": precondition -180 <= LONGITUDE <= 180 failed
What it means
Validation error from Geolocation.Validate: the longitude supplied for geolocation emulation is outside the valid range [-180, 180]. k6 enforces the same precondition Playwright documents before sending the Emulation.setGeolocationOverride CDP command; the offending value is printed with two decimals.
Source
Thrown at internal/js/modules/k6/browser/common/browser_context_options.go:76
Server string `js:"server"`
Bypass string `js:"bypass"`
}
// Validate validates the [ProxyOptions].
func (p *ProxyOptions) Validate() error {
if p == nil {
return nil
}
if strings.TrimSpace(p.Server) == "" {
return fmt.Errorf("proxy.server must be set")
}
return nil
}
// Validate validates the [Geolocation].
func (g *Geolocation) Validate() error {
if g.Longitude < -180 || g.Longitude > 180 {
return fmt.Errorf(`invalid longitude "%.2f": precondition -180 <= LONGITUDE <= 180 failed`, g.Longitude)
}
if g.Latitude < -90 || g.Latitude > 90 {
return fmt.Errorf(`invalid latitude "%.2f": precondition -90 <= LATITUDE <= 90 failed`, g.Latitude)
}
if g.Accuracy < 0 {
return fmt.Errorf(`invalid accuracy "%.2f": precondition 0 <= ACCURACY failed`, g.Accuracy)
}
return nil
}
// GrantPermissionsOptions is used by BrowserContext.GrantPermissions.
type GrantPermissionsOptions struct {
Origin string
}
View on GitHub (pinned to 93accf6570)
Solutions
- Correct the longitude to a value in [-180, 180], e.g. 139.69 for Tokyo.
- Validate coordinates before passing them when they come from external data.
- Double-check you are not feeding radians or swapping latitude/longitude fields.
Example fix
// before
context.setGeolocation({ latitude: 35.68, longitude: 13969 }); // typo: *100
// after
context.setGeolocation({ latitude: 35.68, longitude: 139.69 }); Defensive patterns
Strategy: validation
Validate before calling
function isValidLongitude(v) {
return Number.isFinite(v) && v >= -180 && v <= 180;
}
if (!isValidLongitude(geo.longitude)) {
throw new Error('longitude must be between -180 and 180 degrees');
}
context.setGeolocation(geo); Type guard
function isValidGeolocation(g) {
return Number.isFinite(g.longitude) && g.longitude >= -180 && g.longitude <= 180 &&
Number.isFinite(g.latitude) && g.latitude >= -90 && g.latitude <= 90 &&
(g.accuracy == null || (Number.isFinite(g.accuracy) && g.accuracy >= 0));
} Prevention
- Validate both coordinate ranges before calling setGeolocation/newContext({geolocation}).
- Confirm your data source uses degrees, not radians.
- Check for swapped latitude/longitude when values are near ±180.
When it happens
Trigger: browser.newContext({ geolocation: { longitude: 200 } }) or context.setGeolocation({ longitude: -181, ... }); any numeric input beyond the range, including values produced by bad math (e.g. degrees+radians mixups or sign errors).
Common situations: Tests passing coordinates in radians where degrees were expected (values like 3.14 are legal but wrong; multiplying wrong can push past 180); data-driven location lists containing typos (200 instead of 20.0); unit mistakes copying from datasets that use [latitude, longitude] ordering.
Related errors
- invalid latitude "%.2f": precondition -90 <= LATITUDE <= 90
- invalid accuracy "%.2f": precondition 0 <= ACCURACY failed
- parsing geo location: %w
- validating geo location: %w
- no cookies provided
AI-assisted analysis of grafana/k6@93accf6570 (2026-08-15).
Data as JSON: /api/errors/05c5aae4f4b74561.
Report an issue: GitHub.