microsoft/playwright · error · Error

geolocation.latitude: precondition -90 <= LATITUDE <= 90 fai

Error message

geolocation.latitude: precondition -90 <= LATITUDE <= 90 failed.

What it means

`verifyGeolocation` enforces latitude within [-90, 90]. Out-of-range values throw with this precondition-style message.

Source

Thrown at packages/playwright-core/src/server/browserContext.ts:790

  if (options.proxy)
    options.proxy = normalizeProxySettings(options.proxy);
  verifyGeolocation(options.geolocation);
}

export function findMatchingHttpCredentials(credentials: HttpCredentials[] | undefined, url: string): HttpCredentials | undefined {
  const origin = new URL(url).origin.toLowerCase();
  return credentials?.find(c => !c.origin || c.origin.toLowerCase() === origin);
}

export function verifyGeolocation(geolocation?: types.Geolocation): asserts geolocation is types.Geolocation {
  if (!geolocation)
    return;
  geolocation.accuracy = geolocation.accuracy || 0;
  const { longitude, latitude, accuracy } = geolocation;
  if (longitude < -180 || longitude > 180)
    throw new Error(`geolocation.longitude: precondition -180 <= LONGITUDE <= 180 failed.`);
  if (latitude < -90 || latitude > 90)
    throw new Error(`geolocation.latitude: precondition -90 <= LATITUDE <= 90 failed.`);
  if (accuracy < 0)
    throw new Error(`geolocation.accuracy: precondition 0 <= ACCURACY failed.`);
}

export function verifyClientCertificates(clientCertificates?: types.BrowserContextOptions['clientCertificates']) {
  if (!clientCertificates)
    return;
  for (const cert of clientCertificates) {
    if (!cert.origin)
      throw new Error(`clientCertificates.origin is required`);
    if (!cert.cert && !cert.key && !cert.passphrase && !cert.pfx)
      throw new Error('None of cert, key, passphrase or pfx is specified');
    if (cert.cert && !cert.key)
      throw new Error('cert is specified without key');
    if (!cert.cert && cert.key)
      throw new Error('key is specified without cert');
    if (cert.pfx && (cert.cert || cert.key))
      throw new Error('pfx is specified together with cert, key or passphrase');

View on GitHub (pinned to c8fc3bf8d3)

Solutions

  1. Clamp latitude to [-90, 90] before passing
  2. Double-check that latitude and longitude aren't swapped
  3. Validate input ranges before calling setGeolocation

Example fix

// before
await context.setGeolocation({ longitude: 0, latitude: 120 });

// after
await context.setGeolocation({ longitude: 0, latitude: Math.max(-90, Math.min(90, 120)) });
Defensive patterns

Strategy: validation

Validate before calling

function validateLat(lat: number): number {
  if (lat < -90 || lat > 90) throw new Error(`latitude out of range: ${lat}`);
  return lat;
}
await context.setGeolocation({ longitude: lon, latitude: validateLat(lat) });

Prevention

When it happens

Trigger: `context.setGeolocation({ longitude: 0, latitude: 95 })` or `newContext({ geolocation: { latitude: -120 } })`.

Common situations: Sign/typo errors in coordinates; unverified data from external sources; latitude/longitude swapped (longitude values can exceed ±90).

Related errors


AI-assisted analysis of microsoft/playwright@c8fc3bf8d3 (2026-08-12). Data as JSON: /api/errors/b74cd336a4adf903. Report an issue: GitHub.