{"record":{"id":"b3334f06e7ed9634","repo":"microsoft/playwright","slug":"invalid-geolocation-format-should-be-lat-long","errorCode":null,"errorMessage":"Invalid geolocation format, should be \"lat,long\". For example --geolocation=\"37.819722,-122.478611\"","messagePattern":"Invalid geolocation format, should be \"lat,long\"\\. For example --geolocation=\"37\\.819722,-122\\.478611\"","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"packages/playwright-core/src/cli/browserActions.ts","lineNumber":123,"sourceCode":"      if (isNaN(width) || isNaN(height))\n        throw new Error('bad values');\n      contextOptions.viewport = { width, height };\n    } catch (e) {\n      throw new Error('Invalid viewport size format: use \"width,height\", for example --viewport-size=\"800,600\"');\n    }\n  }\n\n  // Geolocation\n\n  if (options.geolocation) {\n    try {\n      const [latitude, longitude] = options.geolocation.split(',').map(n => parseFloat(n.trim()));\n      contextOptions.geolocation = {\n        latitude,\n        longitude\n      };\n    } catch (e) {\n      throw new Error('Invalid geolocation format, should be \"lat,long\". For example --geolocation=\"37.819722,-122.478611\"');\n    }\n    contextOptions.permissions = ['geolocation'];\n  }\n\n  // User agent\n\n  if (options.userAgent)\n    contextOptions.userAgent = options.userAgent;\n\n  // Lang\n\n  if (options.lang)\n    contextOptions.locale = options.lang;\n\n  // Color scheme\n\n  if (options.colorScheme)\n    contextOptions.colorScheme = options.colorScheme as 'dark' | 'light';","sourceCodeStart":105,"sourceCodeEnd":141,"githubUrl":"https://github.com/microsoft/playwright/blob/c8fc3bf8d31542d59b4d4d9eaab1df93ff541dc6/packages/playwright-core/src/cli/browserActions.ts#L105-L141","documentation":"Thrown by the `--geolocation` CLI option handler when parsing the value as `latitude,longitude` fails. The handler splits on `,`, trims, and `parseFloat`s both parts inside a try; any failure (including NaN results from non-numeric input) is rethrown as the format error.","triggerScenarios":"Running `playwright open --geolocation=...` with a malformed value: `--geolocation=37.8` (missing longitude), `--geolocation=abc,def`, `--geolocation=37,-122,0` (extra component depends on parse path).","commonSituations":"Typo dropping the comma; using DMS coordinates instead of decimal degrees; copy-paste of a maps URL that includes extra fields; locale separator confusion.","solutions":["Provide decimal `lat,long`, e.g. `--geolocation=\"37.819722,-122.478611\"`.","Convert DMS to decimal degrees before passing.","Quote the value to protect the comma from the shell."],"exampleFix":"# before\nnpx playwright open --geolocation=37.819722 https://example.com\n\n# after\nnpx playwright open --geolocation=\"37.819722,-122.478611\" https://example.com","handlingStrategy":"validation","validationCode":"function parseGeolocation(raw: string): { latitude: number; longitude: number } {\n  const parts = (raw ?? '').split(',');\n  if (parts.length !== 2) throw new Error('Use \"lat,long\"');\n  const [lat, lng] = parts.map(s => parseFloat(s.trim()));\n  if (!Number.isFinite(lat) || !Number.isFinite(lng) || Math.abs(lat) > 90 || Math.abs(lng) > 180)\n    throw new Error('lat must be [-90,90], long must be [-180,180]');\n  return { latitude: lat, longitude: lng };\n}","typeGuard":"function isGeolocationString(v: string): boolean {\n  const m = v.match(/^(-?\\d+(?:\\.\\d+)?),(-?\\d+(?:\\.\\d+)?)$/);\n  if (!m) return false;\n  const [, lat, lng] = m;\n  return Math.abs(+lat) <= 90 && Math.abs(+lng) <= 180;\n}","tryCatchPattern":"try {\n  return parseGeolocation(raw);\n} catch (e) {\n  if (/Invalid geolocation format/.test(e.message)) {\n    throw new Error(`Expected decimal \"lat,long\", got ${JSON.stringify(raw)}`);\n  }\n  throw e;\n}","preventionTips":["Use decimal degrees, not DMS.","Quote `--geolocation=\"lat,long\"`.","Validate ranges (lat in [-90,90], long in [-180,180])."],"tags":["cli","geolocation","validation","user-input"],"backgroundTag":null,"analyzedSha":"c8fc3bf8d31542d59b4d4d9eaab1df93ff541dc6","analyzedAt":"2026-08-12T07:26:36.950Z","schemaVersion":2},"datasetVersion":"2026-08-12T13:17:24.610Z"}