Skip to content

Getting started

This walks through launching a browser, opening a page, navigating to a local file, and tearing everything down.

Start the driver

WWW::Playwright.start spawns the Node sidecar and returns a driver handle.

1
2
3
use WWW::Playwright;

my $playwright = WWW::Playwright.start;

Launch a browser

launch starts Chromium. It is headless by default; pass :!headless to see a window.

1
2
my $browser = $playwright.launch;          # headless
# my $browser = $playwright.launch(:!headless);

Open a context and a page

A context is an isolated browser session, the right boundary for one test. Each context owns its own pages.

1
2
my $context = $browser.new-context;
my $page    = $context.new-page;

goto returns the HTTP status of the navigation response.

1
2
my $status = $page.goto('file:///path/to/hello.html');
say $status;   # 200

Tear down

Close from the inside out, then stop the sidecar.

1
2
3
4
5
$page.close;
$context.close;
$browser.close;

$playwright.stop;

stop closes the sidecar's stdin, which closes any browser the sidecar still holds before the Node process exits.