BrowserContext
Playwright\Browser\BrowserContextInterface
Methods
clock()
ClockInterfaceThe context's clock, to fake and advance time.
function clock(): ClockInterface
credentials()
CredentialsInterfaceThe context's virtual WebAuthn authenticator, to seed and read passkeys.
function credentials(): CredentialsInterface
setGeolocation()
voidSets the context's geolocation; null coordinates clear it.
function setGeolocation(?float $latitude, ?float $longitude, ?float $accuracy = 0): void
setOffline()
voidToggles the context's network offline or back online.
function setOffline(bool $offline): void
addCookies()
voidfunction addCookies(array $cookies): void
addInitScript()
voidfunction addInitScript(string $script): void
setExtraHTTPHeaders()
voidSet extra HTTP headers for every request made by pages in this context.
function setExtraHTTPHeaders(array $headers): void
clearCookies()
voidfunction clearCookies(array $options = []): void
deleteCookie()
voidDelete all cookies with the given name across domain and path variants.
function deleteCookie(string $name): void
clearPermissions()
voidfunction clearPermissions(): void
close()
voidfunction close(): void
isClosed()
boolWhether the context is closed, including when its browser was closed instead.
function isClosed(): bool
cookies()
arrayfunction cookies(?array $urls = null): array
exposeBinding()
voidfunction exposeBinding(string $name, callable $callback): void
exposeFunction()
voidfunction exposeFunction(string $name, callable $callback): void
grantPermissions()
voidfunction grantPermissions(array $permissions): void
newPage()
PageInterfacefunction newPage(array $options = []): PageInterface
pages()
arrayfunction pages(): array
browser()
?BrowserInterfaceThe browser this context belongs to, or null for a persistent context. Contexts obtained from Browser::context() or Browser::newContext() always carry their browser.
function browser(): ?BrowserInterface
storageState()
arrayGet storage state as array (legacy method).
function storageState(?string $path = null): array
getStorageState()
StorageStateGet storage state as StorageState object.
function getStorageState(): StorageState
setStorageState()
voidLoad storage state from StorageState object.
function setStorageState(StorageState $storageState): void
saveStorageState()
voidSave storage state to file.
function saveStorageState(string $filePath): void
loadStorageState()
voidLoad storage state from file.
function loadStorageState(string $filePath): void
route()
voidfunction route(string $url, callable $handler): void
unroute()
voidfunction unroute(string $url, ?callable $handler = null): void
unrouteAll()
voidRemoves every route registered on this context 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
getEnv()
?stringfunction getEnv(string $name): ?string
tracing()
TracingInterfaceTracing helper associated with this context.
function tracing(): TracingInterface
startTracing()
voidfunction startTracing(PageInterface $page, array $options = []): void
stopTracing()
voidfunction stopTracing(PageInterface $page, string $path): void
setNetworkThrottling()
voidSet network throttling configuration.
function setNetworkThrottling(NetworkThrottling $throttling): void
disableNetworkThrottling()
voidDisable network throttling.
function disableNetworkThrottling(): void
waitForEvent()
arrayfunction waitForEvent(string $event, ?callable $predicate = null, ?int $timeout = null): array
waitForPopup()
PageInterfacefunction waitForPopup(callable $action, array $options = []): PageInterface
request()
APIRequestContextInterfaceAPI testing helper associated with this context. Requests made with this API will use context cookies.
function request(): APIRequestContextInterface
setDefaultTimeout()
voidSets the default maximum time for methods that accept a timeout option.
function setDefaultTimeout(int $timeout): void
setDefaultNavigationTimeout()
voidSets the default maximum time for navigation methods.
function setDefaultNavigationTimeout(int $timeout): void