feat(page): Introduce page.setGeolocation method (#3160)

Fixes #1077
This commit is contained in:
Andrey Lushnikov
2018-08-31 18:04:12 +01:00
committed by GitHub
parent 10009973fb
commit 17029281a9
3 changed files with 54 additions and 0 deletions

View File

@@ -144,6 +144,20 @@ class Page extends EventEmitter {
});
}
/**
* @param {!{longitude: number, latitude: number, accuracy: (number|undefined)}} options
*/
async setGeolocation(options) {
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._client.send('Emulation.setGeolocationOverride', {longitude, latitude, accuracy});
}
/**
* @return {!Puppeteer.Target}
*/