BrowserContextBuilder

Playwright\Browser\BrowserContextBuilder

Fluent helper to build BrowserContext options arrays. This class does not change any runtime behavior. It only helps produce the associative array expected by Browser::newContext([...]) and Playwright::chromium(['context' => [...]]).

Methods

create()

self
function create(): self

withViewport()

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

withUserAgent()

self
function withUserAgent(string $userAgent): self

withLocale()

self
function withLocale(string $locale): self

withTimezoneId()

self
function withTimezoneId(string $timezoneId): self

withStorageState()

self
function withStorageState(array|string $state): self

withDownloadsPath()

self
function withDownloadsPath(string $path): self

withRecordVideoDir()

self
function withRecordVideoDir(string $dir): self

withColorScheme()

self
function withColorScheme(string $scheme): self

withDeviceScaleFactor()

self
function withDeviceScaleFactor(int|float $factor): self

withIsMobile()

self
function withIsMobile(bool $isMobile = true): self

withHasTouch()

self
function withHasTouch(bool $hasTouch = true): self

withPermissions()

self
function withPermissions(array $permissions): self

toArray()

array

Export as array suitable for Browser::newContext([...]).

function toArray(): array