microsoft/playwright · error · Error
geolocation.accuracy: precondition 0 <= ACCURACY failed.
Error message
geolocation.accuracy: precondition 0 <= ACCURACY failed.
What it means
`verifyGeolocation` enforces a non-negative accuracy. Note that `accuracy` defaults to 0 when falsy, so this only fires when an explicit negative accuracy is supplied.
Solutions
- Pass a non-negative accuracy, or omit it (defaults to 0)
- Validate input: `accuracy = Math.max(0, accuracy)`
Example fix
// before
await context.setGeolocation({ longitude: 0, latitude: 0, accuracy: -10 });
// after
await context.setGeolocation({ longitude: 0, latitude: 0, accuracy: 10 }); Defensive patterns
Strategy: validation
Validate before calling
function normalizeAccuracy(a?: number): number | undefined {
if (a === undefined) return undefined;
if (a < 0) throw new Error(`accuracy must be >= 0 (got ${a})`);
return a;
}
await context.setGeolocation({ longitude: lon, latitude: lat, accuracy: normalizeAccuracy(acc) }); Prevention
- Omit accuracy (defaults to 0) or pass a non-negative value
- Validate computed accuracy values before use
- Don't derive accuracy from deltas that can go negative
When it happens
Trigger: `context.setGeolocation({ longitude: 0, latitude: 0, accuracy: -5 })` or `newContext({ geolocation: { accuracy: -1 } })`.
Common situations: Configs computing accuracy from deltas that go negative; copy-paste errors; treating accuracy as a confidence percentage with negative semantics.
Related errors
- geolocation.latitude: precondition -90 <= LATITUDE <= 90…
- geolocation.longitude: precondition -180 <= LONGITUDE <=…
- Browser userDataDir is not supported in isolated mode.
- Cannot use --mobile together with --device, pick one.
- clientCertificates.origin is required
AI-assisted analysis of microsoft/playwright@f1d33b5029 (2026-08-12).
Data as JSON: /api/errors/08b2d2b58c2a8371.
Report an issue: GitHub.
Appendix: source
Thrown at packages/playwright-core/src/server/browserContext.ts:806
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)
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)View on GitHub (pinned to f1d33b5029)