PHP code example of playwright-php / devices

1. Go to this page and download the library: Download playwright-php/devices library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

playwright-php / devices example snippets


use Playwright\Device\DeviceRegistry;

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

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

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();

$landscape = $device->landscape();

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