Playwright allows overriding various parameters of the device where the browser is running:
- viewport size, device scale factor, touch support
- locale, timezone
- color scheme
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.
Playwright 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.
All pages created in the context above will share the user agent specified:
Create a context with custom viewport size:
Allow 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:
- browserContext.grantPermissions(permissions[, options])
Create a context with
"geolocation" permissions granted:
Change the location later:
Note you can only change geolocation for all pages in the context.
Create a context with dark or light mode. Pages created in this context will follow this color scheme preference.