{"record":{"id":"08b2d2b58c2a8371","repo":"microsoft/playwright","slug":"geolocation-accuracy-precondition-0-accuracy-f","errorCode":null,"errorMessage":"geolocation.accuracy: precondition 0 <= ACCURACY failed.","messagePattern":"geolocation\\.accuracy: precondition 0 <= ACCURACY failed\\.","errorType":"validation","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"packages/playwright-core/src/server/browserContext.ts","lineNumber":792,"sourceCode":"  verifyGeolocation(options.geolocation);\n}\n\nexport function findMatchingHttpCredentials(credentials: HttpCredentials[] | undefined, url: string): HttpCredentials | undefined {\n  const origin = new URL(url).origin.toLowerCase();\n  return credentials?.find(c => !c.origin || c.origin.toLowerCase() === origin);\n}\n\nexport function verifyGeolocation(geolocation?: types.Geolocation): asserts geolocation is types.Geolocation {\n  if (!geolocation)\n    return;\n  geolocation.accuracy = geolocation.accuracy || 0;\n  const { longitude, latitude, accuracy } = geolocation;\n  if (longitude < -180 || longitude > 180)\n    throw new Error(`geolocation.longitude: precondition -180 <= LONGITUDE <= 180 failed.`);\n  if (latitude < -90 || latitude > 90)\n    throw new Error(`geolocation.latitude: precondition -90 <= LATITUDE <= 90 failed.`);\n  if (accuracy < 0)\n    throw new Error(`geolocation.accuracy: precondition 0 <= ACCURACY failed.`);\n}\n\nexport function verifyClientCertificates(clientCertificates?: types.BrowserContextOptions['clientCertificates']) {\n  if (!clientCertificates)\n    return;\n  for (const cert of clientCertificates) {\n    if (!cert.origin)\n      throw new Error(`clientCertificates.origin is required`);\n    if (!cert.cert && !cert.key && !cert.passphrase && !cert.pfx)\n      throw new Error('None of cert, key, passphrase or pfx is specified');\n    if (cert.cert && !cert.key)\n      throw new Error('cert is specified without key');\n    if (!cert.cert && cert.key)\n      throw new Error('key is specified without cert');\n    if (cert.pfx && (cert.cert || cert.key))\n      throw new Error('pfx is specified together with cert, key or passphrase');\n  }\n}","sourceCodeStart":774,"sourceCodeEnd":810,"githubUrl":"https://github.com/microsoft/playwright/blob/c8fc3bf8d31542d59b4d4d9eaab1df93ff541dc6/packages/playwright-core/src/server/browserContext.ts#L774-L810","documentation":"`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.","triggerScenarios":"`context.setGeolocation({ longitude: 0, latitude: 0, accuracy: -5 })` or `newContext({ geolocation: { accuracy: -1 } })`.","commonSituations":"Configs computing accuracy from deltas that go negative; copy-paste errors; treating accuracy as a confidence percentage with negative semantics.","solutions":["Pass a non-negative accuracy, or omit it (defaults to 0)","Validate input: `accuracy = Math.max(0, accuracy)`"],"exampleFix":"// before\nawait context.setGeolocation({ longitude: 0, latitude: 0, accuracy: -10 });\n\n// after\nawait context.setGeolocation({ longitude: 0, latitude: 0, accuracy: 10 });","handlingStrategy":"validation","validationCode":"function normalizeAccuracy(a?: number): number | undefined {\n  if (a === undefined) return undefined;\n  if (a < 0) throw new Error(`accuracy must be >= 0 (got ${a})`);\n  return a;\n}\nawait context.setGeolocation({ longitude: lon, latitude: lat, accuracy: normalizeAccuracy(acc) });","typeGuard":null,"tryCatchPattern":null,"preventionTips":["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"],"tags":["geolocation","validation","config"],"backgroundTag":null,"analyzedSha":"c8fc3bf8d31542d59b4d4d9eaab1df93ff541dc6","analyzedAt":"2026-08-12T07:26:36.950Z","schemaVersion":2},"datasetVersion":"2026-08-12T13:17:24.610Z"}