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:
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:
#
API reference#
ViewportCreate a context with custom viewport size:
#
API reference#
Locale & timezone#
API reference#
PermissionsAllow all pages in the context to show system notifications:
Grant all pages in the existing context access to current location:
Grant notifications access from a specific domain:
Revoke all permissions:
#
API reference- browser.newContext([options])
- browserContext.grantPermissions(permissions[, options])
- browserContext.clearPermissions()
#
GeolocationCreate a context with "geolocation"
permissions granted:
Change the location later:
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.