user-agent
strings. But if your site relies on device-specific browser features, an iPhone emulation running in a Chromium browser might lead to false positives.
This guide explains how to define viewport sizes, device pixel ratio and user-agent
strings using Playwright.
Defining the user agent string
If your site parses the user agent string to serve a different experience to mobile users, define theuserAgent
in your automation scripts.
emulate-mobile.spec.ts
Defining viewport size and pixel density
If your site follows responsive web design practices and renders elements depending on device viewport size, define a mobile viewport and pixel density.emulate-mobile-viewport.spec.ts
Use built-in device registries
Playwright includes a built-in device registry to access mobile device characteristics quickly. Leverage the pre-defined devices to emulate mobile devices.emulate-mobile-builtin.spec.ts