grafana/k6 · error

invalid latitude "%.2f": precondition -90 <= LATITUDE <= 90

Error message

invalid latitude "%.2f": precondition -90 <= LATITUDE <= 90 failed

What it means

Validation error from Geolocation.Validate: the latitude supplied for geolocation emulation is outside the valid range [-90, 90]. As with longitude, k6 checks the precondition before invoking the CDP emulation command and rejects the whole call, printing the invalid latitude.

Source

Thrown at internal/js/modules/k6/browser/common/browser_context_options.go:79

// 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

  1. Correct the latitude to [-90, 90] (e.g. 35.68).
  2. If the value looks like a valid longitude (>90), you almost certainly swapped the latitude and longitude fields — swap them back.
  3. Validate coordinates from data files before use.

Example fix

// before
context.setGeolocation({ latitude: 139.69, longitude: 35.68 }); // fields swapped

// after
context.setGeolocation({ latitude: 35.68, longitude: 139.69 });
Defensive patterns

Strategy: validation

Validate before calling

function isValidLatitude(v) {
  return Number.isFinite(v) && v >= -90 && v <= 90;
}
if (!isValidLatitude(geo.latitude)) {
  throw new Error('latitude must be between -90 and 90 degrees (are lat/lng swapped?)');
}
context.setGeolocation(geo);

Type guard

function isValidLatitude(v) {
  return Number.isFinite(v) && v >= -90 && v <= 90;
}

Prevention

When it happens

Trigger: browser.newContext({ geolocation: { latitude: 95 } }) or context.setGeolocation({ latitude: -120 }); any latitude beyond the poles' ±90 limit.

Common situations: Swapped latitude/longitude arguments (a longitude like 139 fed as latitude exceeds 90 immediately — this is the most common cause); typos in coordinate fixtures; generated data with sign or magnitude errors.

Related errors


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