Playwright device descriptors in PHP (mobile & desktop screens, user agents, viewports, scale factors, touch/mobile flags).

Maintainers

Package info

github.com/playwright-php/devices

pkg:composer/playwright-php/devices

Transparency log

Fund package maintenance!

smnandre

Statistics

Installs: 134

Dependents: 0

Suggesters: 0

Stars: 2

Open Issues: 0

v1.1.0 2026-07-20 02:28 UTC

This package is auto-updated.

Last update: 2026-08-13 03:42:10 UTC


README

Playwright PHP

  PHP Version   CI   Release   License

Playwright PHP Devices

Use Microsoft Playwright's device descriptors from PHP for repeatable viewport, user agent, touch, and mobile emulation.

Installation

composer require playwright-php/devices

The package requires PHP 8.2+. Install playwright-php/playwright as well when using descriptors in browser automation.

Quick Start

Load a descriptor by its upstream Playwright device name:

use Playwright\Device\DeviceRegistry;

$device = (new DeviceRegistry())->get('iPhone 15 Pro');

echo $device->getName();
echo $device->getUserAgent();

Use its properties when creating a Playwright browser context:

use Playwright\Playwright;

$context = Playwright::webkit([
    'context' => [
        'userAgent' => $device->getUserAgent(),
        'viewport' => $device->getViewport(),
        'screen' => $device->getScreen(),
        'deviceScaleFactor' => $device->getDeviceScaleFactor(),
        'isMobile' => $device->isMobile(),
        'hasTouch' => $device->hasTouch(),
    ],
]);

$page = $context->newPage();
$page->goto('https://example.com');

echo $page->title();

$context->close();

The descriptor exposes its preferred browser engine through getDefaultBrowserType(). Choose the matching Playwright engine when browser-specific behavior matters.

Orientation

Descriptors that provide a landscape viewport can be changed without mutating the original object:

$landscape = $device->landscape();

echo $landscape->getViewport()['width'];

Calling landscape() on a descriptor without landscape data throws an InvalidArgumentException.

Catalog

Use DeviceRegistry::has() to check a name and DeviceRegistry::all() to retrieve the complete catalog.

The generated device catalog lists every available descriptor and its browser, screen, viewport, scale, mobile, and touch values.

Device descriptors emulate browser-visible properties. They do not reproduce physical hardware, operating-system UI, network conditions, or device performance.

Documentation

Contributing

Contributions are welcome. Before submitting a pull request, run:

composer validate --strict
vendor/bin/php-cs-fixer fix --dry-run --diff
vendor/bin/phpstan analyse
vendor/bin/phpunit

License

Playwright PHP Devices is released under the MIT License.