Emulation
Playwright allows overriding various parameters of the device where the browser is running:
- viewport size, device scale factor, touch support
- locale, timezone
- color scheme
- geolocation
Most of these parameters are configured during the browser context construction, but some of them such as viewport size can be changed for individual pages.
#
DevicesPlaywright comes with a registry of device parameters for selected mobile devices. It can be used to simulate browser behavior on a mobile device:
- Sync
- Async
All pages created in the context above will share the same device parameters.
#
API reference#
User agentAll pages created in the context above will share the user agent specified:
- Sync
- Async
#
API reference#
ViewportCreate a context with custom viewport size:
- Sync
- Async
#
API reference#
Locale & timezone- Sync
- Async
#
API reference#
PermissionsAllow all pages in the context to show system notifications:
- Sync
- Async
Grant all pages in the existing context access to current location:
- Sync
- Async
Grant notifications access from a specific domain:
- Sync
- Async
Revoke all permissions:
- Sync
- Async
#
API reference- browser.new_context(**kwargs)
- browser_context.grant_permissions(permissions, **kwargs)
- browser_context.clear_permissions()
#
GeolocationCreate a context with "geolocation"
permissions granted:
- Sync
- Async
Change the location later:
- Sync
- Async
Note you can only change geolocation for all pages in the context.
#
API reference#
Color scheme and mediaCreate a context with dark or light mode. Pages created in this context will follow this color scheme preference.
- Sync
- Async