PlaywrightPHP

Made in JS Unleashed in PHP

PHP 8.2+
Release 1.1.0
License MIT

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();
Browsers & devices

Launch real engines

Start Chromium, Firefox, or WebKit with PHP-ready presets for desktop and mobile runs.

<?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.

Finders keepers

Smart Locators

Find elements with typed locators and auto-wait. No sleeps, no manual polling.

<?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.

Input Control

Click. Type. Tap.

Drive the browser with trusted input events. Automate file uploads, drag-and-drop, and keyboard shortcuts directly from PHP to match real user behavior.

<?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.

This is not a test.

Flaky-free Assertions

Built-in matchers with auto-wait and auto-retry so tests stay stable when the UI isn't.

<?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.

Debug +

Time-travel debugging

Control time with clock API. Fast-forward timers, test expiry, and time-dependent flows.

<?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.

Press Start

Get started

Go from zero to full browser automation in under 60 seconds.

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

# 2. Download browsers
vendor/bin/playwright install
Get Involved

Want to help?

Playwright PHP thrives on community support. Whether you write code, sponsor development, or share your knowledge, your help drives the project forward.

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.