puppeteer/puppeteer · error · Error
Invalid latitude "${latitude}": precondition -90 <= LATITUDE
Error message
Invalid latitude "${latitude}": precondition -90 <= LATITUDE <= 90 failed. What it means
Thrown by EmulationManager.setGeolocation when the latitude value is outside the [-90, 90] range. Client-side precondition mirroring the Emulation.setGeolocationOverride CDP check, raised before the command is sent so the offending value is obvious.
Source
Thrown at packages/puppeteer-core/src/cdp/EmulationManager.ts:562
state.geoLocation
? {
longitude: state.geoLocation.longitude,
latitude: state.geoLocation.latitude,
accuracy: state.geoLocation.accuracy,
}
: undefined,
);
}
async setGeolocation(options: GeolocationOptions): Promise<void> {
const {longitude, latitude, accuracy = 0} = options;
if (longitude < -180 || longitude > 180) {
throw new Error(
`Invalid longitude "${longitude}": precondition -180 <= LONGITUDE <= 180 failed.`,
);
}
if (latitude < -90 || latitude > 90) {
throw new Error(
`Invalid latitude "${latitude}": precondition -90 <= LATITUDE <= 90 failed.`,
);
}
if (accuracy < 0) {
throw new Error(
`Invalid accuracy "${accuracy}": precondition 0 <= ACCURACY failed.`,
);
}
await this.#geoLocationState.setState({
active: true,
geoLocation: {
longitude,
latitude,
accuracy,
},
});
}
View on GitHub (pinned to d484e21c17)
Solutions
- Validate latitude is within [-90, 90] before calling setGeolocation.
- Double-check that you are not passing a longitude (>90) into the latitude field.
- Sanitize input coordinates from untrusted sources with a clamp helper.
- Add a unit test on your coordinate-building code to catch out-of-range values.
Example fix
// before
await page.setGeolocation({ longitude: -73, latitude: 120 }); // throws
// after: validate
const latitude = clamp(rawLat, -90, 90);
await page.setGeolocation({ longitude: -73, latitude }); Defensive patterns
Strategy: validation
Validate before calling
if (!Number.isFinite(latitude) || latitude < -90 || latitude > 90) {
throw new Error(`latitude out of range: ${latitude}`);
} Type guard
function isValidLatitude(v: unknown): v is number {
return typeof v === 'number' && Number.isFinite(v) && v >= -90 && v <= 90;
} Prevention
- Validate latitude to [-90, 90].
- Make sure you are not passing a longitude into the latitude field.
- Clamp untrusted coordinate sources.
When it happens
Trigger: Calling page.setGeolocation with latitude < -90 or > 90; magnitude error from a malformed fixture; sign confusion on southern latitudes.
Common situations: Coordinates pulled from external data without bounds checking; tests using extreme values; copy-paste of a latitude where a longitude was expected (longitudes can exceed +/-90).
Related errors
- Invalid longitude "${longitude}": precondition -180 <= LONGI
- Invalid accuracy "${accuracy}": precondition 0 <= ACCURACY f
- Invalid longitude "${longitude}": precondition -180 <= LONGI
- Invalid latitude "${latitude}": precondition -90 <= LATITUDE
- Invalid accuracy "${accuracy}": precondition 0 <= ACCURACY f
AI-assisted analysis of puppeteer/puppeteer@d484e21c17 (2026-08-12).
Data as JSON: /api/errors/732d92cec2082f4e.
Report an issue: GitHub.