Page

Playwright\Page\PageInterface

Methods

pause()

self

Opens Playwright Inspector and pauses script execution.

function pause(): self

evaluateHandle()

JSHandleInterface

Returns a handle to the result instead of a serialized copy, so a DOM node or a live object survives the round trip. Dispose the handle once done with it, otherwise it pins its target until the page closes.

function evaluateHandle(string $expression, mixed $arg = null): JSHandleInterface

locator()

LocatorInterface
function locator(string $selector, array|LocatorOptions $options = []): LocatorInterface

getByAltText()

LocatorInterface
function getByAltText(string|Regex $text, array|LocatorOptions $options = []): LocatorInterface

getByLabel()

LocatorInterface
function getByLabel(string|Regex $text, array|LocatorOptions $options = []): LocatorInterface

getByPlaceholder()

LocatorInterface
function getByPlaceholder(string|Regex $text, array|LocatorOptions $options = []): LocatorInterface

getByRole()

LocatorInterface
function getByRole(string $role, array|GetByRoleOptions $options = []): LocatorInterface

getByTestId()

LocatorInterface
function getByTestId(string $testId, array|LocatorOptions $options = []): LocatorInterface

getByText()

LocatorInterface
function getByText(string|Regex $text, array|LocatorOptions $options = []): LocatorInterface

getByTitle()

LocatorInterface
function getByTitle(string|Regex $text, array|LocatorOptions $options = []): LocatorInterface

goto()

?ResponseInterface
function goto(string $url, array|GotoOptions $options = []): ?ResponseInterface

click()

self
function click(string $selector, array|ClickOptions $options = []): self

dragAndDrop()

self
function dragAndDrop(string $source, string $target, array|DragAndDropOptions $options = []): self

altClick()

self
function altClick(string $selector, array|ClickOptions $options = []): self

controlClick()

self
function controlClick(string $selector, array|ClickOptions $options = []): self

shiftClick()

self
function shiftClick(string $selector, array|ClickOptions $options = []): self

type()

self
function type(string $selector, string $text, array|TypeOptions $options = []): self

screenshot()

string
function screenshot(?string $path = null, array|ScreenshotOptions $options = []): string

pdf()

string
function pdf(?string $path = null, array|PdfOptions $options = []): string

pdfContent()

string
function pdfContent(array|PdfOptions $options = []): string

content()

?string
function content(): ?string

consoleMessages()

array

Console messages already recorded for this page, oldest first. Unlike the console event, this reads history, so messages logged before any listener existed are still returned. The default filter keeps only what was logged since the last navigation.

function consoleMessages(array $options = []): array

clearConsoleMessages()

self

Discards the recorded console history without touching event listeners.

function clearConsoleMessages(): self

clearPageErrors()

self

Discards the uncaught page errors recorded so far.

function clearPageErrors(): self

ariaSnapshot()

string

Captures the accessibility tree of the whole page as YAML.

function ariaSnapshot(array|AriaSnapshotOptions $options = []): string

addInitScript()

self

Queues a script to run before any of the page's own scripts. It runs again on every navigation and in every frame the page creates, so it is the place to stub an API or seed state a page reads at startup.

function addInitScript(string $script): self

evaluate()

mixed
function evaluate(string $expression, mixed $arg = null): mixed

emulateMedia()

self

Overrides the CSS media type and media features the page reports. An omitted feature keeps whatever override is in place; pass 'no-override' to give it back to the browser default.

function emulateMedia(array|EmulateMediaOptions $options = []): self

requestGC()

self

Asks the browser to collect garbage, so a WeakRef held by the page can be observed as cleared. Collection is best effort, never guaranteed.

function requestGC(): self

waitForSelector()

LocatorInterface
function waitForSelector(string $selector, array|WaitForSelectorOptions $options = []): LocatorInterface

close()

void
function close(): void

isClosed()

bool
function isClosed(): bool

bringToFront()

self
function bringToFront(): self

context()

BrowserContextInterface
function context(): BrowserContextInterface

clock()

ClockInterface

Fake timers for this page. The clock belongs to the browser context, so installing it here affects every page of that context.

function clock(): ClockInterface

video()

?VideoInterface

Video recorded for this page, or null when the context does not record one. The file is only complete once the page is closed, so save or delete it after closing the page.

function video(): ?VideoInterface

hideHighlight()

self

Removes every highlight painted on this page by LocatorInterface::highlight().

function hideHighlight(): self

cookies()

array
function cookies(?array $urls = null): array

goBack()

self
function goBack(array|NavigationHistoryOptions $options = []): self

goForward()

self
function goForward(array|NavigationHistoryOptions $options = []): self

reload()

self
function reload(array|NavigationHistoryOptions $options = []): self

setContent()

self
function setContent(string $html, array|SetContentOptions $options = []): self

url()

string
function url(): string

title()

string
function title(): string

viewportSize()

?array
function viewportSize(): ?array

setViewportSize()

self
function setViewportSize(int $width, int $height): self

setDefaultNavigationTimeout()

self
function setDefaultNavigationTimeout(int $timeout): self

setDefaultTimeout()

self
function setDefaultTimeout(int $timeout): self

setExtraHTTPHeaders()

self
function setExtraHTTPHeaders(array $headers): self

waitForLoadState()

self
function waitForLoadState(string $state = 'load', array|WaitForLoadStateOptions $options = []): self

waitForFunction()

self
function waitForFunction(string $pageFunction, mixed $arg = null, array|WaitForFunctionOptions $options = []): self

waitForURL()

self
function waitForURL($url, array|WaitForUrlOptions $options = []): self

addScriptTag()

self
function addScriptTag(array|ScriptTagOptions $options): self

addStyleTag()

self
function addStyleTag(array|StyleTagOptions $options): self

frameLocator()

FrameLocatorInterface
function frameLocator(string $selector): FrameLocatorInterface

keyboard()

KeyboardInterface
function keyboard(): KeyboardInterface

mouse()

MouseInterface
function mouse(): MouseInterface

touchscreen()

TouchscreenInterface

Touch input for this page. The owning context must have been created with hasTouch enabled, otherwise the browser ignores the events.

function touchscreen(): TouchscreenInterface

localStorage()

WebStorageInterface

The localStorage of the page's current origin.

function localStorage(): WebStorageInterface

sessionStorage()

WebStorageInterface

The sessionStorage of the page's current origin.

function sessionStorage(): WebStorageInterface

screencast()

ScreencastInterface

The page's screencast, to record a video and annotate it.

function screencast(): ScreencastInterface

events()

PageEventHandlerInterface
function events(): PageEventHandlerInterface

route()

void
function route(string $url, callable $handler): void

unroute()

void
function unroute(string $url, ?callable $handler = null): void

unrouteAll()

void

Removes every route registered on this page in one call. 'behavior' decides what happens to handlers still running: wait for them, wait but swallow their errors, or return without waiting.

function unrouteAll(array $options = []): void

handleDialog()

void
function handleDialog(string $dialogId, bool $accept, ?string $promptText = null): void

getPageIdForTransport()

string
function getPageIdForTransport(): string

waitForEvents()

void
function waitForEvents(): void

waitForPopup()

self
function waitForPopup(callable $action, array|WaitForPopupOptions $options = []): self

waitForResponse()

ResponseInterface
function waitForResponse($url, array|WaitForResponseOptions $options = []): ResponseInterface

waitForRequest()

RequestInterface

Waits for a request whose URL matches the given Playwright glob. PHP cannot act while this call blocks, so the trigger travels with it: an 'action' entry in $options holds a JavaScript expression the bridge evaluates once the listener is armed.

function waitForRequest(string $url, array|WaitForRequestOptions $options = []): RequestInterface

opener()

?PageInterface

The page that opened this one, or null when nothing did.

function opener(): ?PageInterface

requests()

array

Network requests recorded for this page, oldest first. These are snapshots taken by the bridge, not live handles: members that need the Node object, such as response(), return null on them.

function requests(): array

setInputFiles()

self

Set files to an input element with type="file".

function setInputFiles(string $selector, array $files, array|SetInputFilesOptions $options = []): self

mainFrame()

FrameInterface

Get a handle to the main frame.

function mainFrame(): FrameInterface

frames()

array

List top-level child frames of the main frame.

function frames(): array

frame()

?FrameInterface

Find a top-level frame by name or URL.

function frame(array|FrameQueryOptions $options): ?FrameInterface

request()

APIRequestContextInterface

API testing helper associated with this page. This method returns the same instance as browserContext.request() on the page's context.

function request(): APIRequestContextInterface