Headless launch
Launch headless Chromium with Playwright PHP, open a web page, and print its title. A runnable example to check your installation.
This example launches Chromium without showing a browser window, opens example.com, and prints the page title.
Use it as the smallest headless smoke check after installation.
Run it
php content/examples/headless.php
Expected output:
Title: Example Domain
Headless mode is the default choice for CI because it does not require a visible desktop session.
What it demonstrates
headless => trueruns the browser without a visible window.newPage()opens a tab.goto()navigates to a URL.title()reads browser state back into PHP.
Go next
- Install first: Setup
- Compare headed mode: Headed run
- Learn browsers: Browsers
Source
headless.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;
$context = Playwright::chromium([
'headless' => true,
]);
$page = $context->newPage();
$page->goto('https://example.com');
echo 'Title: '.$page->title().PHP_EOL;
$context->close();