Choose a browser

Loop over Chromium, Firefox, and WebKit and print versions.

This example runs the same small flow in Chromium, Firefox, and WebKit, then prints each browser version.

Use it to verify that your local install has all engines available and to understand where browser choice enters the API.

Run it

bash
php content/examples/browser-choice.php

Expected output:

text
Browser: chromium ... | URL: https://www.whatismybrowser.com/
Browser: firefox ... | URL: https://www.whatismybrowser.com/
Browser: webkit ... | URL: https://www.whatismybrowser.com/

Versions vary by installed browser binaries.

What it demonstrates

  • PlaywrightFactory::create() exposes browser builders.
  • Each browser engine launches independently.
  • The same page flow can run across Chromium, Firefox, and WebKit.
  • Cross-browser checks are useful after the single-browser flow is stable.

Go next

Source

browser-choice.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\Browser\BrowserInterface;
use Playwright\PlaywrightFactory;

$playwright = PlaywrightFactory::create();
$browsers = [
    'chromium' => $playwright->chromium(),
    'firefox' => $playwright->firefox(),
    'webkit' => $playwright->webkit(),
];

foreach ($browsers as $type => $browserBuilder) {
    $browser = $browserBuilder->withHeadless()->launch();
    assert($browser instanceof BrowserInterface);

    $page = $browser->newPage();
    $page->goto('https://www.whatismybrowser.com/');
    $page->locator('text=Your Browser is:')->waitFor();
    echo sprintf('Browser: %s %s | URL: %s', $type, $browser->version(), $page->url())."\n";

    $page->close();
    $browser->close();
}