To reproduce a mobile browser location in Playwright, set latitude and longitude on the browser context and grant that context the geolocation permission. Configure a mobile device profile separately: it emulates browser-facing device characteristics, but does not set the location or turn the test into automation on a physical phone.
This guide covers Playwright Test and direct BrowserContext setup, changing or removing a location during a test, and the separate Android automation route. Examples use illustrative coordinates, not anyone’s actual position.
What you need to configure
A page reads its location through browser geolocation APIs. For Playwright’s documented emulation workflow, provide coordinates and grant the relevant permission. The permission and coordinates are context-level settings; a device descriptor configures other browser-emulation characteristics. See the official Playwright emulation guide and BrowserContext API.
- Location: latitude and longitude, optionally an accuracy value.
- Permission: include
'geolocation'so pages in the context may read the emulated location. - Mobile profile, if needed: choose a device descriptor for browser-facing settings such as user agent, viewport, screen size, and touch.
Keep location separate from timezone: a coordinate does not set the browser’s timezone. Configure timezone independently when the scenario requires it, as shown in the emulation documentation.
#1 Best Overall
- 【Strong Adsorption】The inspiration of the silicone phone suction case comes from the adhesive force of the octopus. Each suction cup phone mount is 3.15 inches long and 2.17 inches wide, with 24 independent suction cups providing a stronger and more stable suction force, so you don't have to worry about your phone falling during use.
- 【Back of Phone Suction Grip】Remove the adhesive film on the phone suction cup and stick it on the phone case. You can then fix the phone on any smooth surface, which is very convenient. (The phone suction cup cannot be removed and reused after being attached to the phone case. It is recommended to attach it to a regular phone case, not a valuable one.)
- 【Widely Used】Our non-slip silicone phone sticky grip mount attaches to almost any flat phone case and make it compatible with common mobile phones such as iPhone and Android.You can shoot, watch videos or video calls in the kitchen, gym, dance studio, bathroom and other places.
- 【Capture the Wonderful Picture】Whether you are a TikTok creator or just like to share videos and photos, this phone suction cup can help you hands-free capture wonderful videos and photos for sharing with friends.
- 【Note】You can fix the phone suction cup on a smooth surface such as a mirror or glass. If necessary, wipe the suction cup with a damp cloth to obtain stronger suction. Before releasing your hand, make sure the phone is firmly fixed. (Not applicable to rough walls, wooden surfaces, and other uneven surfaces)
Set a fixed location in Playwright Test
For a project-wide default, put the device profile, coordinates, and permission in the project’s use configuration. This makes the settings reusable across that project’s tests.
// playwright.config.js
const { defineConfig, devices } = require('@playwright/test');
module.exports = defineConfig({
projects: [
{
name: 'mobile-chromium',
use: {
...devices['iPhone 13'],
geolocation: { latitude: 41.890221, longitude: 12.492348 },
permissions: ['geolocation'],
},
},
],
});
The iPhone 13 name is used in Playwright’s documentation example; use a device descriptor present in the device registry of the Playwright version installed in your project. To use these defaults for just one test rather than a project, provide them in that test’s configuration:
const { test, expect, devices } = require('@playwright/test');
test.use({
...devices['iPhone 13'],
geolocation: { latitude: 41.890221, longitude: 12.492348 },
permissions: ['geolocation'],
});
test('shows content for the emulated location', async ({ page }) => {
await page.goto('https://example.com');
// Assert the page behavior your application implements for this location.
});
Replace the sample URL and assertions with your own application. The example location is only a test input. Project and test configuration are useful for stable defaults; use a direct context when a script needs to create contexts with different settings.
Set a location in a direct BrowserContext
When using Playwright’s library API, pass the coordinates and permission to browser.newContext(), then create pages from that context. This complete example uses Chromium and the Playwright device registry:
The Tool Desk
Outbyte PC Repair FREERepair Windows errors before they cause bigger problemsFix Now →Outbyte Driver Updater FREEScan for outdated or missing drivers - takes under a minuteDriver Scan →Rank #2
- SUPERIOR COMFORT — Unlike traditional circular ear buds, the design of EarPods is defined by the geometry of the ear. Which makes them more comfortable for more people than any other ear bud–style headphones.
- HIGH-QUALITY AUDIO — The speakers inside EarPods have been engineered to maximize sound output and minimize sound loss, which means you get high-quality audio.
- BUILT-IN REMOTE — EarPods with USB-C plug also include a built-in remote that lets you adjust the volume, control the playback of music and video, and answer or end calls with a pinch of the cord.
- COMPATIBILITY — Works with all devices that have a USB-C port.
- INTEGRATED MICROPHONE — A built-in microphone precisely captures your voice while you’re on the phone, taking a FaceTime call, or summoning Siri — so you’re always heard loud and clear.
const { chromium, devices } = require('playwright');
(async () => {
const browser = await chromium.launch();
const context = await browser.newContext({
...devices['iPhone 13'],
geolocation: { latitude: 41.890221, longitude: 12.492348 },
permissions: ['geolocation'],
});
const page = await context.newPage();
try {
await page.goto('https://example.com');
// Exercise the page's location-dependent behavior here.
} finally {
await context.close();
await browser.close();
}
})();
Install Playwright in the project and ensure its browser is available before running the script. The try/finally cleanup closes the context and browser even if navigation or a test assertion fails. For non-mobile browser-context geolocation, omit the device spread but retain geolocation and permissions.
Change or remove the location during a test
Use context.setGeolocation() when a scenario moves between locations instead of keeping one fixed position. The change applies to all pages in that context. Keep pages that should share the updated location in the same context; a separate context has its own settings. The API also accepts null or undefined to emulate an unavailable position. See BrowserContext.setGeolocation.
const { chromium } = require('playwright');
(async () => {
const browser = await chromium.launch();
const context = await browser.newContext({
geolocation: { latitude: 40.7128, longitude: -74.0060 },
permissions: ['geolocation'],
});
const page = await context.newPage();
try {
await page.goto('https://example.com');
// Move every page in this context to a second illustrative position.
await context.setGeolocation({ latitude: 34.0522, longitude: -118.2437 });
// Emulate location unavailable when the scenario requires it.
await context.setGeolocation(null);
} finally {
await context.close();
await browser.close();
}
})();
Adapt the sequence to your application’s behavior and wait for the page to react before asserting results. A location update changes the context setting; your application still needs to request or respond to location changes in the way its own code supports.
Valid coordinate values
- Latitude must be between
-90and90. - Longitude must be between
-180and180. - The optional
accuracyvalue must be non-negative and defaults to zero when omitted.
These constraints are documented by the BrowserContext API. Use realistic values for the behavior you intend to test, but do not treat a chosen coordinate as a report of a real user’s position.
Free tools Windows power users keep installed
One-click scans. No signup required.
Rank #3
- Secure Hold: Our PopSockets adhesive phone grip gives your cell phone a secure, comfortable hold in hand to help prevent drops while texting, taking photos, or scrolling on the go. Designed to stick firmly to most phone cases and devices.
- Hands-Free Made Easy: Easily turn your PopSocket into a phone stand to prop up your phone anywhere — perfect for watching videos, video calls, or following recipes. A must-have phone holder that keeps your device secure and ready for anything.
- Compatibility: Works with all phones, tablets, and Kindles. Sticks best to smooth, hard plastic cases and may not adhere to silicone or textured cases. Easily swap your PopTop to change up your style — just close the grip, press down, twist 90°, and snap on a new top.
- Black PopSockets: Simple, refined, and endlessly versatile — a timeless essential for any phone.
- PopSockets Ecosystem: Mix and match your favorite PopSockets products — from grips and wallets to cases and mounts — all designed to work together seamlessly.
Choose the right approach for the test
| Approach | Best fit | What it configures |
|---|---|---|
Playwright Test use configuration |
Reusable project defaults or a test-specific setup | Coordinates, permissions, and any selected device settings for the configured tests. |
| Direct BrowserContext options | Library scripts or scenarios that create custom contexts | Coordinates, permissions, and optional device settings when the context is created. |
context.setGeolocation() |
A scenario that changes location during a test | Updates the location for every page in that context; accepts null or undefined for unavailable position. |
For browser-based mobile testing, device emulation is generally the direct route: combine a device descriptor with context geolocation. Playwright’s isMobile option affects whether the meta viewport tag is taken into account and enables touch events; the API notes it is unsupported in Firefox. Neither a device descriptor nor isMobile proves that the test is running on a physical handset. Read the Browser API and emulation guide for the options applicable to your browser and version.
When you need Android device automation
Mobile browser emulation and automating Chrome for Android or Android WebView on an Android device or AVD are different testing targets. Choose Android automation only if the application or test depends on the Android browser or device itself, rather than browser-facing mobile settings. Playwright documents Android support as experimental and describes additional setup and limitations in its Android API documentation.
- Android automation requires Android/ADB setup; it is not a prerequisite for setting geolocation on a regular browser context.
- The documentation identifies authenticated ADB and an awake device for screenshots among the setup or limitation considerations.
- Because the route is experimental, confirm that its current capabilities and constraints suit your exact test before making it the basis of a test suite.
Do not use Android setup merely to supply latitude and longitude to a page: context geolocation is the simpler documented mechanism for that browser-emulation scenario.
Troubleshoot location tests
The page reports permission denied
Coordinates alone are not the complete setup. Add 'geolocation' to the context’s permissions, or grant it through the appropriate context or origin permissions API. The BrowserContext documentation recommends browserContext.grantPermissions() when granting pages permission to read geolocation. Check that you are configuring the context the page actually uses.
Recommended Free Tools
Rank #4
- [360 ° Flexible Rotation Design] Comes with a rotatable lanyard ring that supports 360 ° free rotation, effectively solving the problem of twisted and tangled lanyards
- [Wide compatibility] The ultra-thin 0.02-inch design does not block the charging port at all, and both wired and wireless charging can be used directly without removing the pad. Compatible with most smartphones such as iPhone, compatible with various wristbands, lanyards, crossbody straps, and keychains
- [Durable and Portable Material] Premium rust-resistant stainless steel material with good flexibility, which not only avoids scratching the phone case, but also has excellent anti rust and anti fading performance
- [Multi scenario Practical] Paired with a lanyard or wristband, hands-free use can be achieved. The phone is within reach and not easily dropped, ideal for daily commuting and outdoor activities. Suitable for full coverage phone cases, does not support half coverage phone cases
- [Quality Service] If you find any damage or other issues with the product upon receipt, please contact us immediately. We will handle it quickly
The page returns no location or an unexpected position
- Confirm that the page was created in the context where you set the coordinates and permission.
- Check latitude and longitude against their documented ranges and ensure accuracy, if supplied, is non-negative.
- If you changed position, keep the relevant pages in the same context and verify that your application reacts to a position change.
- If you deliberately called
setGeolocation(null)or passedundefined, the expected result is an unavailable position, not a coordinate.
The same permission setup works in one browser but not another
Supported permissions vary across browsers and browser versions, and Playwright notes that permission support can change after updates. Check the current BrowserContext API for the browser/version combination in use, then update the test configuration or choose a supported browser for that scenario. Do not assume identical permission behavior across all engines.
The page has the wrong local time
Geolocation and timezone are independent emulation settings. Set the timezone explicitly if the test depends on local time, and do not expect changing latitude and longitude to change the browser clock’s timezone.
The test looks mobile but misses a device-specific issue
Device descriptors emulate browser-facing parameters; they are not equivalent to all hardware and operating-system behavior on a physical handset. If the failure depends on Chrome for Android, WebView, ADB, or the device itself, evaluate the separate Android automation path rather than interpreting a mobile viewport as physical-device coverage.
Independent reader supportYour contribution helps us test, update, and keep practical guides available for everyone.Performance, isolation, and reliability
Use a fixed context configuration for repeatable location scenarios, and create distinct contexts when tests need independent starting locations or permissions. Playwright’s browser contexts provide isolated environments, described in its browser-context isolation guide. Context-level settings make the scope explicit: pages sharing a context share its geolocation, while a separate context lets a test avoid coupling its state to another scenario.
Do these 3 things before closing this tab:
1Scan for outdated or missing drivers - takes under a minute2Repair Windows errors before they cause bigger problems3Fix the driver behind crashes, sound loss and screen glitchesBest Value
- 【PKYAA Double Sided Silicone Suction Phone Case Mount】PKYAA With Double Sided 40 Strong and Reliable individual suction cups, PKYAA provides a thicken and upgraded universal silicon suction mount for your phone.
- 【Friendly to Content Creators】If you are a content creator or an online influencer, you can create videos anywhere with this suction mount completely hands free with this silicone cell phone mount for cases.
- 【HANDS-FREE & Adhere to Mirrors】This Double Sided silicone suction phone case mount allows you to stick your phone to the mirror easily. No longer holding your phone in one hand to watch video tutorials while making up.
- 【Strong Grip on the Smooth Surface】You can easily hang your phone anywhere with a smooth surface. All you do is you clean off your phone and smooth surface. It is STURDY and it not only sticks to mirrors, it also sticks to windows, it sticks to refrigerators, tiles and other clean, flat surfaces.
- 【Press Down Firmly Every 30 Minutes】Use your palm or fingers to press the phone down firmly and check it's secure before letting go. Apply even pressure for a few seconds to allow the suction cup to adhere properly. To maintain the grip and prevent accidental falls, it's a good practice to periodically reapply pressure to the suction cup.
Prefer changing a location with setGeolocation() only when movement or position-unavailable behavior is part of the test. For a scenario that needs one stable location, set it when constructing the context or in test configuration. This keeps the setup aligned with the behavior being tested and makes failures easier to diagnose. Permission support remains browser- and version-dependent, so pin and validate the browser combination used in continuous integration when geolocation is a critical test requirement.
Or skip the browser setup
ScreenshotNeo captures website screenshots and PDFs; it does not configure Playwright geolocation or replace a test that verifies location-dependent behavior. After your Playwright test has established the required page state, you can use its screenshot API to capture a site directly. See the ScreenshotNeo website and API documentation for request options.
curl -G "https://api.screenshotneo.com/v1/shot" -d access_key=YOUR_API_KEY --data-urlencode url=https://example.com -o shot.webp
ScreenshotNeo removes cookie or consent banners, newsletter popups, and chat widgets before capture; each of those steps can be turned off. Bot checks, blank pages, timeouts, failed loads, and cache hits are not billed, and responses identify page verdict and billing status in headers. Its MCP server provides take_screenshot, get_page_info, and capture_pdf tools for Claude, Cursor, and other MCP clients. The Free plan includes 1,000 screenshots per month with no card; paid plans start at $5 for 3,000 screenshots.
Sign up free for 1,000 screenshots a month with no card.
Quick wins for a faster PC:
Repair Windows errors before they cause bigger problemsFix Now →Fix the driver behind crashes, sound loss and screen glitchesFind Drivers →Further official references
- Emulation — device profiles, geolocation, locale, timezone, and related settings.
- BrowserContext API — context geolocation, permissions, and changing the emulated position.
- Browser API — browser context and device-related API details.
- Test generator — device selection examples in Playwright code generation.
- Android API — Android automation and its documented constraints.
- Browser contexts — test isolation concepts.
Frequently Asked Questions
Can I emulate GPS movement in Playwright?
Yes. Call context.setGeolocation() with successive coordinates; the update applies to pages in that context. Your application must handle location changes for the page to reflect them.
Does setting Playwright geolocation change the computer’s location or IP address?
No. The documented setting emulates the browser geolocation result; it is not a change to the host device’s physical location or network address.
Can I use Playwright geolocation with Firefox?
Geolocation permissions vary by browser and version. Also note that Playwright’s isMobile option is unsupported in Firefox; consult the current permission support in the BrowserContext API for your installed version.
Quick Recap
Product prices and availability are accurate as of the date/time indicated and are subject to change. Any price and availability information displayed on Amazon at the time of purchase will apply.

