Headed run

Open a visible Chromium window with Playwright PHP, navigate to a web page, and save a screenshot. A runnable example for local debugging.

This example launches Chromium in headed mode, opens example.com, and saves a screenshot.

Use it when you want to see the browser while learning or debugging. Keep normal CI runs headless unless the job is explicitly visual.

Run it

bash
php content/examples/browser-screen.php

Expected output:

text
Url: https://example.com/
Screenshot saved to: .../var/playwright-artifacts/examples/screenshot_example.png

The browser window should appear locally. The screenshot is written to the examples artifact directory.

What it demonstrates

  • headless => false shows the browser.
  • goto() navigates the page.
  • screenshot() writes visual evidence to disk.

Do not use headed mode as a fix for CI. Use it to understand what is happening, then keep the unattended test stable.

Go next

Source

browser-screen.php
php
<?php

declare(strict_types=1);

/*
 * This file is part of the community-maintained Playwright PHP project.
 * It is not affiliated with or endorsed by Microsoft.
 *
 * (c) 2025-Present - Playwright PHP - https://github.com/playwright-php
 *
 * For the full copyright and license information, please view the LICENSE
 * file that was distributed with this source code.
 */

require_once __DIR__.'/../../vendor/autoload.php';

use Playwright\Playwright;

$artifactDir = __DIR__.'/../../var/playwright-artifacts/examples';
is_dir($artifactDir) || mkdir($artifactDir, 0777, true);

$context = Playwright::chromium([
    'headless' => false,
]);
$page = $context->newPage();

$page->goto('https://example.com');
echo 'Url: '.$page->url()."\n";

$file = $page->screenshot($artifactDir.'/screenshot_example.png');
echo 'Screenshot saved to: '.$file."\n";

$page->close();
$context->close();