{"record":{"id":"e1ddcf712a70df77","repo":"microsoft/playwright","slug":"geolocation-longitude-precondition-180-longit","errorCode":null,"errorMessage":"geolocation.longitude: precondition -180 <= LONGITUDE <= 180 failed.","messagePattern":"geolocation\\.longitude: precondition -180 <= LONGITUDE <= 180 failed\\.","errorType":"validation","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"packages/playwright-core/src/server/browserContext.ts","lineNumber":788,"sourceCode":"  if (!options.viewport && !options.noDefaultViewport)\n    options.viewport = { width: 1280, height: 720 };\n  if (options.proxy)\n    options.proxy = normalizeProxySettings(options.proxy);\n  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');","sourceCodeStart":770,"sourceCodeEnd":806,"githubUrl":"https://github.com/microsoft/playwright/blob/c8fc3bf8d31542d59b4d4d9eaab1df93ff541dc6/packages/playwright-core/src/server/browserContext.ts#L770-L806","documentation":"`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()`.","triggerScenarios":"`context.setGeolocation({ longitude: 200, latitude: 0 })` or `newContext({ geolocation: { longitude: -181, latitude: 0 } })`.","commonSituations":"Off-by-one sign errors; data sourced from configs/databases with unverified ranges; copy-paste of coordinates with missing decimal points.","solutions":["Clamp longitude to [-180, 180] before passing","Validate config/user input against the range and reject early with a clearer error"],"exampleFix":"// before\nawait context.setGeolocation({ longitude: 200, latitude: 40 });\n\n// after\nawait context.setGeolocation({ longitude: 200 % 360, latitude: 40 });\n// or clamp: Math.max(-180, Math.min(180, lon))","handlingStrategy":"validation","validationCode":"function clampLongitude(lon: number): number {\n  if (lon < -180 || lon > 180) {\n    // normalize or clamp:\n    return Math.max(-180, Math.min(180, lon));\n  }\n  return lon;\n}\nawait context.setGeolocation({ longitude: clampLongitude(lon), latitude });","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Clamp longitude to [-180, 180] before setGeolocation","Validate coordinate inputs from external/config sources","Add a unit test on the clamp helper"],"tags":["geolocation","validation","config"],"backgroundTag":null,"analyzedSha":"c8fc3bf8d31542d59b4d4d9eaab1df93ff541dc6","analyzedAt":"2026-08-12T07:26:36.950Z","schemaVersion":2},"datasetVersion":"2026-08-12T13:17:24.610Z"}