microsoft/playwright · error · Error
Invalid geolocation format, should be "lat,long". For exampl
Error message
Invalid geolocation format, should be "lat,long". For example --geolocation="37.819722,-122.478611"
What it means
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.
Source
Thrown at packages/playwright-core/src/cli/browserActions.ts:123
if (isNaN(width) || isNaN(height))
throw new Error('bad values');
contextOptions.viewport = { width, height };
} catch (e) {
throw new Error('Invalid viewport size format: use "width,height", for example --viewport-size="800,600"');
}
}
// Geolocation
if (options.geolocation) {
try {
const [latitude, longitude] = options.geolocation.split(',').map(n => parseFloat(n.trim()));
contextOptions.geolocation = {
latitude,
longitude
};
} catch (e) {
throw new Error('Invalid geolocation format, should be "lat,long". For example --geolocation="37.819722,-122.478611"');
}
contextOptions.permissions = ['geolocation'];
}
// User agent
if (options.userAgent)
contextOptions.userAgent = options.userAgent;
// Lang
if (options.lang)
contextOptions.locale = options.lang;
// Color scheme
if (options.colorScheme)
contextOptions.colorScheme = options.colorScheme as 'dark' | 'light';View on GitHub (pinned to c8fc3bf8d3)
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.
Example fix
# before npx playwright open --geolocation=37.819722 https://example.com # after npx playwright open --geolocation="37.819722,-122.478611" https://example.com
Defensive patterns
Strategy: validation
Validate before calling
function parseGeolocation(raw: string): { latitude: number; longitude: number } {
const parts = (raw ?? '').split(',');
if (parts.length !== 2) throw new Error('Use "lat,long"');
const [lat, lng] = parts.map(s => parseFloat(s.trim()));
if (!Number.isFinite(lat) || !Number.isFinite(lng) || Math.abs(lat) > 90 || Math.abs(lng) > 180)
throw new Error('lat must be [-90,90], long must be [-180,180]');
return { latitude: lat, longitude: lng };
} Type guard
function isGeolocationString(v: string): boolean {
const m = v.match(/^(-?\d+(?:\.\d+)?),(-?\d+(?:\.\d+)?)$/);
if (!m) return false;
const [, lat, lng] = m;
return Math.abs(+lat) <= 90 && Math.abs(+lng) <= 180;
} Try / catch
try {
return parseGeolocation(raw);
} catch (e) {
if (/Invalid geolocation format/.test(e.message)) {
throw new Error(`Expected decimal "lat,long", got ${JSON.stringify(raw)}`);
}
throw e;
} Prevention
- Use decimal degrees, not DMS.
- Quote `--geolocation="lat,long"`.
- Validate ranges (lat in [-90,90], long in [-180,180]).
When it happens
Trigger: 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).
Common situations: Typo dropping the comma; using DMS coordinates instead of decimal degrees; copy-paste of a maps URL that includes extra fields; locale separator confusion.
Related errors
- Invalid viewport size format: use "width,height", for exampl
- Device descriptor not found: '${options.device}', available
- Error while parsing selector `${selector}` - selector cannot
- PDF creation is only working with Chromium
- Invalid color scheme, should be one of "light", "dark"
AI-assisted analysis of microsoft/playwright@c8fc3bf8d3 (2026-08-12).
Data as JSON: /api/errors/b3334f06e7ed9634.
Report an issue: GitHub.