Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore(docs): clarify connection method via BrowserType.connect #34560

Merged
merged 3 commits into from
Jan 30, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 22 additions & 2 deletions docs/src/api/class-browsertype.md
Original file line number Diff line number Diff line change
Expand Up @@ -87,15 +87,31 @@ class BrowserTypeExamples

## async method: BrowserType.connect
* since: v1.8
* langs: js
- returns: <[Browser]>

This method attaches Playwright to an existing browser instance. When connecting to another browser launched via `BrowserType.launchServer` in Node.js, the major and minor version needs to match the client version (1.2.3 → is compatible with 1.2.x).
This method attaches Playwright to an existing browser instance created via [`method: BrowserType.launchServer`].

:::note
The major and minor version of the Playwright instance that connects needs to match the version of Playwright that launches the browser (1.2.3 → is compatible with 1.2.x).
:::

## async method: BrowserType.connect
* since: v1.8
* langs: python, csharp, java
- returns: <[Browser]>

This method attaches Playwright to an existing browser instance created via `BrowserType.launchServer` in Node.js.

:::note
The major and minor version of the Playwright instance that connects needs to match the version of Playwright that launches the browser (1.2.3 → is compatible with 1.2.x).
:::

### param: BrowserType.connect.wsEndpoint
* since: v1.10
- `wsEndpoint` <[string]>

A browser websocket endpoint to connect to.
A Playwright browser websocket endpoint to connect to. You obtain this endpoint via [`method: BrowserServer.wsEndpoint`].

### option: BrowserType.connect.headers
* since: v1.11
Expand Down Expand Up @@ -152,6 +168,10 @@ The default browser context is accessible via [`method: Browser.contexts`].
Connecting over the Chrome DevTools Protocol is only supported for Chromium-based browsers.
:::

:::note
This connection is significantly lower fidelity than the Playwright protocol connection via [`method: BrowserType.connect`]. If you are experiencing issues or attempting to use advanced functionality, you probably want to use [`method: BrowserType.connect`].
:::

**Usage**

```js
Expand Down
34 changes: 26 additions & 8 deletions packages/playwright-core/types/types.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14554,6 +14554,11 @@ export interface BrowserType<Unused = {}> {
*
* **NOTE** Connecting over the Chrome DevTools Protocol is only supported for Chromium-based browsers.
*
* **NOTE** This connection is significantly lower fidelity than the Playwright protocol connection via
* [browserType.connect(wsEndpoint[, options])](https://playwright.dev/docs/api/class-browsertype#browser-type-connect).
* If you are experiencing issues or attempting to use advanced functionality, you probably want to use
* [browserType.connect(wsEndpoint[, options])](https://playwright.dev/docs/api/class-browsertype#browser-type-connect).
*
* **Usage**
*
* ```js
Expand All @@ -14579,6 +14584,11 @@ export interface BrowserType<Unused = {}> {
*
* **NOTE** Connecting over the Chrome DevTools Protocol is only supported for Chromium-based browsers.
*
* **NOTE** This connection is significantly lower fidelity than the Playwright protocol connection via
* [browserType.connect(wsEndpoint[, options])](https://playwright.dev/docs/api/class-browsertype#browser-type-connect).
* If you are experiencing issues or attempting to use advanced functionality, you probably want to use
* [browserType.connect(wsEndpoint[, options])](https://playwright.dev/docs/api/class-browsertype#browser-type-connect).
*
* **Usage**
*
* ```js
Expand All @@ -14593,10 +14603,14 @@ export interface BrowserType<Unused = {}> {
*/
connectOverCDP(options: ConnectOverCDPOptions & { wsEndpoint?: string }): Promise<Browser>;
/**
* This method attaches Playwright to an existing browser instance. When connecting to another browser launched via
* `BrowserType.launchServer` in Node.js, the major and minor version needs to match the client version (1.2.3 → is
* compatible with 1.2.x).
* @param wsEndpoint A browser websocket endpoint to connect to.
* This method attaches Playwright to an existing browser instance created via
* [browserType.launchServer([options])](https://playwright.dev/docs/api/class-browsertype#browser-type-launch-server).
*
* **NOTE** The major and minor version of the Playwright instance that connects needs to match the version of
* Playwright that launches the browser (1.2.3 → is compatible with 1.2.x).
*
* @param wsEndpoint A Playwright browser websocket endpoint to connect to. You obtain this endpoint via
* [browserServer.wsEndpoint()](https://playwright.dev/docs/api/class-browserserver#browser-server-ws-endpoint).
* @param options
*/
connect(wsEndpoint: string, options?: ConnectOptions): Promise<Browser>;
Expand All @@ -14607,10 +14621,14 @@ export interface BrowserType<Unused = {}> {
* @deprecated
*/
/**
* This method attaches Playwright to an existing browser instance. When connecting to another browser launched via
* `BrowserType.launchServer` in Node.js, the major and minor version needs to match the client version (1.2.3 → is
* compatible with 1.2.x).
* @param wsEndpoint A browser websocket endpoint to connect to.
* This method attaches Playwright to an existing browser instance created via
* [browserType.launchServer([options])](https://playwright.dev/docs/api/class-browsertype#browser-type-launch-server).
*
* **NOTE** The major and minor version of the Playwright instance that connects needs to match the version of
* Playwright that launches the browser (1.2.3 → is compatible with 1.2.x).
*
* @param wsEndpoint A Playwright browser websocket endpoint to connect to. You obtain this endpoint via
* [browserServer.wsEndpoint()](https://playwright.dev/docs/api/class-browserserver#browser-server-ws-endpoint).
* @param options
*/
connect(options: ConnectOptions & { wsEndpoint?: string }): Promise<Browser>;
Expand Down
Loading