Some websites request access to your location. This is often used to show a map, find nearby stores, or check delivery availability.
How to set it up
Grant permission to access location
Before simulating location data, allow the website to access the browser’s location. See Granting permissions for more information on how to do that. Use the following permissions:
{ "permissions": ["geolocation"] }
Set the test location
Determine the latitude and longitude coordinates of the location you want to simulate. To get the latitude and longitude, you can use a site like https://plus.codes/map.
For example, Tokyo Tower has these coordinates:
latitude: 35.658563 longitude: 139.745437
Add a Playwright code step
Add the following Playwright code step before the website tries to detect the location:
await context.setGeolocation({ latitude: 35.658563, longitude: 139.745437 });
Additional parameters
You can also include an
accuracy
value in meters if needed:await context.setGeolocation({ latitude: 35.658563, longitude: 139.745437, accuracy: 100 });
To simulate the user’s location being unavailable (e.g., no GPS signal), you can pass in a value of
null
await context.setGeolocation(null);