Exploring the Depths of Playwright: Browser Contexts, Page, APIs and Workers
BrowserContexts provide a way to operate multiple independent browser sessions.
Playwright allows creating "incognito" browser contexts with browser.newContext() method.
This API is used for the Web API testing. You can use it to trigger API endpoints
Good for requests that need to share session data with the browser context
It's not tied to any particular page but inherits the context's configuration, such as user agent and any cookies or local storage data already set within the context. Updates cookies
Best for requests specifically associated with the activity or data of a particular page or headers specific to that page.
Updates cookies
Isolated instance, a standalone request outside of Playwright's page or context scope
Does not use or updates updates cookies from the browser context
These processes are OS processes, running independently, orchestrated by the test runner.
All workers have identical environments and each starts its own browser.