Playwright PHP - Browser Automation

Real browsers.
From PHP.

Full Playwright API, native PHP DX — just real browsers and first-class assertions.

<?php

use Playwright\Playwright;

$browser = Playwright::chromium();
$page = $browser->newPage();

$page->goto('https://playwright-php.dev');

echo $page->title();
echo $page->locator('h1')->textContent();

$page->screenshot('example.png');

$browser->close();
<?php

$browser = Playwright::chromium([
    'headless' => true,
    'viewport' => [
        'width' => 1920,
        'height' => 1080
    ],
    'screen' => [
        'width' => 3840,
        'height' => 2160
    ]
]);

$page = $browser->newPage();
$page->goto('https://www.whatsmybrowser.org');
echo $page->title();

Device presets

Preset viewports for flagship phones.

Headless CI

Headless runs emit traces and HARs.

<?php

$button = $page->getByRole('button', ['name' => 'Add to cart']);
$input = $page->getByLabel('Email');

$products = $page->locator('.product');
$firstProduct = $products->first();
$recentProducts = $products->filter(['hasText' => 'new']);

$price = $products->locator('.price');

Deterministic waits

Auto-wait spans selectors, navigation, and assertions.

Tabs & history

Open tabs, switch contexts, and drive back/forward entirely in PHP.

<?php

// Mouse
$page->locator('#search-input')->hover();
$page->mouse->move(220, 410);

// Keyboard
$page->locator('#search-input')->focus();
$page->keyboard->type('Hello World', ['delay' => 100]);
$page->keyboard->press('Control+A');

// Click, Type, Tap
$page->click('button#add-to-cart');

File uploads

Upload fixtures, streams, buffers like users.

Keyboard macros

Send chords, modifiers, full shortcuts.

<?php

// Assert on page
expect($page)->toHaveTitle('Products - Example Store');
expect($page)->not()->toHaveURL('/error');

// Assert on locators
expect($page->locator('.product-title'))->toBeVisible();
expect($page->locator('button'))->toHaveAttribute('type', 'submit');
expect($page->locator('.grid'))->toHaveCss('display', 'grid');

PHPUnit ready

Drop in assertions into your tests.

Network control

Block or mock assets and API calls.

<?php

$context = Playwright::chromium();
$page = $context->newPage();

$context->startTracing($page);

$page->goto('https://example.com');
$page->click('button');

$context->stopTracing($page, 'trace.zip');
// trace.zip contains DOM snapshots, interactions, and resources loaded

Fast-forward time

Skip timers and intervals instantly.

Video artifacts

Record MP4 runs for handoffs, CI.

# 1. Install the package
composer require playwright-php/playwright

# 2. Download browsers
vendor/bin/playwright install

Contribute

Report bugs, suggest features, or submit pull requests to improve the library.

Sponsor

Support ongoing development and maintenance through GitHub Sponsors.

Feedback

Share your ideas, report issues, or request features to help shape the future of the project.

Spread the word

Write tutorials, share on social media, or tell your team about Playwright PHP.