Playwright Core Classes API
This appendix lists the common APIs of Playwright core classes for quick reference.
Playwright Class
Playwright is the entry object of the Playwright Library.
| Methods/Properties | Description |
|---|---|
playwright.chromium | Returns the BrowserType object for Chromium |
playwright.firefox | Returns the BrowserType object for Firefox |
playwright.webkit | Returns the BrowserType object for WebKit |
playwright.request | Returns the APIRequest object |
playwright.selectors | Returns the Selectors object |
BrowserType Class
BrowserType is used to launch and connect to browsers.
| Methods | Description |
|---|---|
browserType.launch(options?) | Launches a browser instance |
browserType.launchPersistentContext(userDataDir, options?) | Launches a persistent context (using a local user data directory) |
browserType.connect(url, options?) | Connects to an already running browser |
browserType.connectOverCDP(url, options?) | Connects to an already running browser via the CDP protocol |
browserType.executablePath() | Returns the browser executable path |
browserType.name() | Returns the browser name |
Browser Class
Browser represents a browser instance.
| Methods/Properties | Description |
|---|---|
browser.newContext(options?) | Creates a new BrowserContext |
browser.newPage(options?) | Creates a new Page in a new Context |
browser.contexts() | Returns a list of all Contexts |
browser.close() | Closes the browser and all pages |
browser.browserType() | Returns the corresponding BrowserType |
browser.version() | Returns the browser version |
browser.isConnected() | Whether connected |
BrowserContext Class
BrowserContext represents an independent browser context.
| Methods | Description |
|---|---|
context.newPage() | Creates a new page |
context.pages() | Returns all open pages |
context.close() | Closes the Context |
context.cookies(urls?) | Gets cookies |
context.addCookies(cookies) | Adds cookies |
context.clearCookies() | Clears all cookies |
context.storageState(options?) | Gets the current storage state (for authentication reuse) |
context.grantPermissions(permissions) | Grants permissions |
context.clearPermissions() | Clears permissions |
context.setGeolocation(geolocation) | Sets geolocation |
context.setExtraHTTPHeaders(headers) | Sets extra HTTP headers |
context.route(url, handler) | Intercepts network requests |
context.unroute(url, handler?) | Cancels interception |
context.exposeFunction(name, fn) | Exposes a function to the page |
context.exposeBinding(name, callback) | Exposes a binding to the page |
BrowserServer Class
BrowserServer represents the browser process launched vialaunchServer()the launched browser process.
| Methods | Description |
|---|---|
browserServer.wsEndpoint() | Returns the WebSocket endpoint URL (for remote connection) |
browserServer.close() | Closes the server and browser |
browserServer.kill() | Forcefully terminates the browser process |