microsoft/playwright · error · Error

geolocation.longitude: precondition -180 <= LONGITUDE <=…

Error message

geolocation.longitude: precondition -180 <= LONGITUDE <= 180 failed.

What it means

`verifyGeolocation` enforces longitude within [-180, 180]. Out-of-range values throw with this precondition-style message. Geolocation is set via `newContext({ geolocation })` or `context.setGeolocation()`.

Solutions

  1. Clamp longitude to [-180, 180] before passing
  2. Validate config/user input against the range and reject early with a clearer error

Example fix

// before
await context.setGeolocation({ longitude: 200, latitude: 40 });

// after
await context.setGeolocation({ longitude: 200 % 360, latitude: 40 });
// or clamp: Math.max(-180, Math.min(180, lon))
Defensive patterns

Strategy: validation

Validate before calling

function clampLongitude(lon: number): number {
  if (lon < -180 || lon > 180) {
    // normalize or clamp:
    return Math.max(-180, Math.min(180, lon));
  }
  return lon;
}
await context.setGeolocation({ longitude: clampLongitude(lon), latitude });

Prevention

When it happens

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

Common situations: Off-by-one sign errors; data sourced from configs/databases with unverified ranges; copy-paste of coordinates with missing decimal points.

Related errors


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

Appendix: source

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

  if (options.proxy)
    options.proxy = normalizeProxySettings(options.proxy);
  if (options.recordVideo?.fps !== undefined && options.recordVideo.fps <= 0)
    throw new Error(`"recordVideo.fps" must be a positive number, got ${options.recordVideo.fps}`);
  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.noCertificate) {
      if (cert.cert || cert.key || cert.passphrase || cert.pfx)
        throw new Error('noCertificate is set together with cert, key, passphrase or pfx');
      continue;
    }
    if (!cert.cert && !cert.key && !cert.passphrase && !cert.pfx)

View on GitHub (pinned to f1d33b5029)