Skip to content
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
4 changes: 2 additions & 2 deletions docs/src/api/class-android.md
Original file line number Diff line number Diff line change
Expand Up @@ -81,9 +81,9 @@ const { _android: android } = require('playwright');
This methods attaches Playwright to an existing Android device.
Use [`method: Android.launchServer`] to launch a new Android server instance.

### param: Android.connect.wsEndpoint
### param: Android.connect.endpoint
* since: v1.28
- `wsEndpoint` <[string]>
- `endpoint` <[string]>

A browser websocket endpoint to connect to.

Expand Down
4 changes: 2 additions & 2 deletions docs/src/api/class-browsertype.md
Original file line number Diff line number Diff line change
Expand Up @@ -95,9 +95,9 @@ This method attaches Playwright to an existing browser instance created via `Bro
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
### param: BrowserType.connect.endpoint
* since: v1.10
- `wsEndpoint` <[string]>
- `endpoint` <[string]>

A Playwright browser websocket endpoint to connect to. You obtain this endpoint via `BrowserServer.wsEndpoint`.

Expand Down
6 changes: 5 additions & 1 deletion packages/devtools/src/grid.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -180,7 +180,11 @@ const SessionChip: React.FC<{ sessionFile: SessionFile; canConnect: boolean; vis
<div className='screencast-container'>
{channel && <Screencast channel={channel} />}
{!canConnect && <div className='screencast-placeholder'>Session closed</div>}
{canConnect && !channel && wsUrl === null && <div className='screencast-placeholder'>Not supported &mdash; v{sessionFile.config.version}</div>}
{canConnect && !channel && wsUrl === null && <div className='screencast-placeholder'>
Session v{sessionFile.config.version} is not compatible with this viewer{model.clientInfo ? ` v${model.clientInfo.version}` : ''}.
<br />
Please update playwright-cli and restart this with "playwright-cli show".
</div>}
{canConnect && !channel && wsUrl === undefined && <div className='screencast-placeholder'>Connecting</div>}
</div>
</a>
Expand Down
20 changes: 10 additions & 10 deletions packages/playwright-client/types/types.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15169,9 +15169,9 @@ 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).
* [browserType.connect(endpoint[, 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).
* [browserType.connect(endpoint[, options])](https://playwright.dev/docs/api/class-browsertype#browser-type-connect).
*
* **Usage**
*
Expand Down Expand Up @@ -15199,9 +15199,9 @@ 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).
* [browserType.connect(endpoint[, 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).
* [browserType.connect(endpoint[, options])](https://playwright.dev/docs/api/class-browsertype#browser-type-connect).
*
* **Usage**
*
Expand All @@ -15222,7 +15222,7 @@ export interface BrowserType<Unused = {}> {
* **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`.
* @param endpoint A Playwright browser websocket endpoint to connect to. You obtain this endpoint via `BrowserServer.wsEndpoint`.
* @param options
*/
connect(wsEndpoint: string, options?: ConnectOptions): Promise<Browser>;
Expand All @@ -15238,7 +15238,7 @@ export interface BrowserType<Unused = {}> {
* **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`.
* @param endpoint A Playwright browser websocket endpoint to connect to. You obtain this endpoint via `BrowserServer.wsEndpoint`.
* @param options
*/
connect(options: ConnectOptions & { wsEndpoint?: string }): Promise<Browser>;
Expand Down Expand Up @@ -15819,7 +15819,7 @@ export interface BrowserType<Unused = {}> {

/**
* Returns the browser app instance. You can connect to it via
* [browserType.connect(wsEndpoint[, options])](https://playwright.dev/docs/api/class-browsertype#browser-type-connect),
* [browserType.connect(endpoint[, options])](https://playwright.dev/docs/api/class-browsertype#browser-type-connect),
* which requires the major/minor client/server version to match (1.2.3 → is compatible with 1.2.x).
*
* **Usage**
Expand Down Expand Up @@ -16818,10 +16818,10 @@ export interface Android {
* This methods attaches Playwright to an existing Android device. Use
* [android.launchServer([options])](https://playwright.dev/docs/api/class-android#android-launch-server) to launch a
* new Android server instance.
* @param wsEndpoint A browser websocket endpoint to connect to.
* @param endpoint A browser websocket endpoint to connect to.
* @param options
*/
connect(wsEndpoint: string, options?: {
connect(endpoint: string, options?: {
/**
* Additional HTTP headers to be sent with web socket connect request. Optional.
*/
Expand Down Expand Up @@ -19103,7 +19103,7 @@ export interface BrowserServer {
* Browser websocket url.
*
* Browser websocket endpoint which can be used as an argument to
* [browserType.connect(wsEndpoint[, options])](https://playwright.dev/docs/api/class-browsertype#browser-type-connect)
* [browserType.connect(endpoint[, options])](https://playwright.dev/docs/api/class-browsertype#browser-type-connect)
* to establish connection to the browser.
*
* Note that if the listen `host` option in `launchServer` options is not specified, localhost will be output anyway,
Expand Down
4 changes: 2 additions & 2 deletions packages/playwright-core/src/cli/client/program.ts
Original file line number Diff line number Diff line change
Expand Up @@ -294,7 +294,7 @@ async function killAllDaemons(): Promise<void> {
const result = execSync(
`powershell -NoProfile -NonInteractive -Command `
+ `"Get-CimInstance Win32_Process `
+ `| Where-Object { $_.CommandLine -like '*-server*' -and $_.CommandLine -like '*--daemon-*' } `
+ `| Where-Object { $_.CommandLine -like '*run-mcp-server*' -or $_.CommandLine -like '*run-cli-server*' } `
+ `| ForEach-Object { Stop-Process -Id $_.ProcessId -Force -ErrorAction SilentlyContinue; $_.ProcessId }"`,
{ encoding: 'utf-8' }
);
Expand All @@ -308,7 +308,7 @@ async function killAllDaemons(): Promise<void> {
const result = execSync('ps aux', { encoding: 'utf-8' });
const lines = result.split('\n');
for (const line of lines) {
if ((line.includes('-server')) && line.includes('--daemon-')) {
if (line.includes('run-mcp-server') || line.includes('run-cli-server')) {
const parts = line.trim().split(/\s+/);
const pid = parts[1];
if (pid && /^\d+$/.test(pid)) {
Expand Down
4 changes: 2 additions & 2 deletions packages/playwright-core/src/client/android.ts
Original file line number Diff line number Diff line change
Expand Up @@ -66,11 +66,11 @@ export class Android extends ChannelOwner<channels.AndroidChannel> implements ap
return await this._serverLauncher.launchServer(options);
}

async connect(wsEndpoint: string, options: Parameters<api.Android['connect']>[1] = {}): Promise<api.AndroidDevice> {
async connect(endpoint: string, options: Parameters<api.Android['connect']>[1] = {}): Promise<api.AndroidDevice> {
return await this._wrapApiCall(async () => {
const deadline = options.timeout ? monotonicTime() + options.timeout : 0;
const headers = { 'x-playwright-browser': 'android', ...options.headers };
const connectParams: channels.LocalUtilsConnectParams = { wsEndpoint, headers, slowMo: options.slowMo, timeout: options.timeout || 0 };
const connectParams: channels.LocalUtilsConnectParams = { endpoint, headers, slowMo: options.slowMo, timeout: options.timeout || 0 };
const connection = await connectOverWebSocket(this._connection, connectParams);

let device: AndroidDevice;
Expand Down
18 changes: 8 additions & 10 deletions packages/playwright-core/src/client/browserType.ts
Original file line number Diff line number Diff line change
Expand Up @@ -122,13 +122,12 @@ export class BrowserType extends ChannelOwner<channels.BrowserTypeChannel> imple
}

connect(options: api.ConnectOptions & { wsEndpoint: string }): Promise<Browser>;
connect(options: api.ConnectOptions & { pipeName: string }): Promise<Browser>;
connect(wsEndpoint: string, options?: api.ConnectOptions): Promise<Browser>;
async connect(optionsOrWsEndpoint: string | (api.ConnectOptions & { wsEndpoint?: string, pipeName?: string }), options?: api.ConnectOptions): Promise<Browser>{
if (typeof optionsOrWsEndpoint === 'string')
return await this._connect({ ...options, wsEndpoint: optionsOrWsEndpoint });
assert(optionsOrWsEndpoint.wsEndpoint || optionsOrWsEndpoint.pipeName, 'Either options.wsEndpoint or options.pipeName is required');
return await this._connect(optionsOrWsEndpoint);
connect(endpoint: string, options?: api.ConnectOptions): Promise<Browser>;
async connect(optionsOrEndpoint: string | (api.ConnectOptions & { wsEndpoint?: string, pipeName?: string }), options?: api.ConnectOptions): Promise<Browser>{
if (typeof optionsOrEndpoint === 'string')
return await this._connect({ ...options, endpoint: optionsOrEndpoint });
assert(optionsOrEndpoint.wsEndpoint, 'options.wsEndpoint is required');
return await this._connect(optionsOrEndpoint);
}

async _connect(params: ConnectOptions): Promise<Browser> {
Expand All @@ -137,10 +136,9 @@ export class BrowserType extends ChannelOwner<channels.BrowserTypeChannel> imple
const deadline = params.timeout ? monotonicTime() + params.timeout : 0;
const headers = { 'x-playwright-browser': this.name(), ...params.headers };
const connectParams: channels.LocalUtilsConnectParams = {
wsEndpoint: params.wsEndpoint,
pipeName: params.pipeName,
endpoint: params.endpoint!,
headers,
exposeNetwork: params.exposeNetwork ?? params._exposeNetwork,
exposeNetwork: params.exposeNetwork,
slowMo: params.slowMo,
timeout: params.timeout || 0,
};
Expand Down
12 changes: 5 additions & 7 deletions packages/playwright-core/src/client/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -96,14 +96,12 @@ export type LaunchOptions = Omit<channels.BrowserTypeLaunchOptions, 'ignoreAllDe
export type LaunchPersistentContextOptions = Omit<LaunchOptions & BrowserContextOptions, 'storageState'>;

export type ConnectOptions = {
wsEndpoint?: string,
pipeName?: string,
endpoint?: string;
headers?: { [key: string]: string; };
exposeNetwork?: string,
_exposeNetwork?: string,
slowMo?: number,
timeout?: number,
logger?: Logger,
exposeNetwork?: string;
slowMo?: number;
timeout?: number;
logger?: Logger;
};
export type LaunchServerOptions = LaunchOptions & {
host?: string,
Expand Down
2 changes: 1 addition & 1 deletion packages/playwright-core/src/client/webSocket.ts
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ class WebSocketTransport implements Transport {
private _ws: WebSocket | undefined;

async connect(params: channels.LocalUtilsConnectParams) {
this._ws = new window.WebSocket(params.wsEndpoint!);
this._ws = new window.WebSocket(params.endpoint);
return [];
}

Expand Down
3 changes: 1 addition & 2 deletions packages/playwright-core/src/protocol/validator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -314,8 +314,7 @@ scheme.LocalUtilsHarUnzipParams = tObject({
});
scheme.LocalUtilsHarUnzipResult = tOptional(tObject({}));
scheme.LocalUtilsConnectParams = tObject({
wsEndpoint: tOptional(tString),
pipeName: tOptional(tString),
endpoint: tString,
headers: tOptional(tAny),
exposeNetwork: tOptional(tString),
slowMo: tOptional(tFloat),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -84,9 +84,9 @@ export class LocalUtilsDispatcher extends Dispatcher<SdkObject, channels.LocalUt
}

async connect(params: channels.LocalUtilsConnectParams, progress: Progress): Promise<channels.LocalUtilsConnectResult> {
if (params.pipeName)
return await this._connectOverPipe(params, progress);
return await this._connectOverWebSocket(params, progress);
if (URL.canParse(params.endpoint))
return await this._connectOverWebSocket(params, progress);
return await this._connectOverPipe(params, progress);
}

private async _connectOverWebSocket(params: channels.LocalUtilsConnectParams, progress: Progress): Promise<channels.LocalUtilsConnectResult> {
Expand All @@ -95,7 +95,7 @@ export class LocalUtilsDispatcher extends Dispatcher<SdkObject, channels.LocalUt
'x-playwright-proxy': params.exposeNetwork ?? '',
...params.headers,
};
const wsEndpoint = await urlToWSEndpoint(progress, params.wsEndpoint!);
const wsEndpoint = await urlToWSEndpoint(progress, params.endpoint);

const transport = await WebSocketTransport.connect(progress, wsEndpoint, { headers: wsHeaders, followRedirects: true, debugLogHeader: 'x-playwright-debug-log' });
const socksInterceptor = new SocksInterceptor(transport, params.exposeNetwork, params.socksProxyRedirectPortForTest);
Expand Down Expand Up @@ -128,7 +128,7 @@ export class LocalUtilsDispatcher extends Dispatcher<SdkObject, channels.LocalUt

private async _connectOverPipe(params: channels.LocalUtilsConnectParams, progress: Progress): Promise<channels.LocalUtilsConnectResult> {
const socket = await new Promise<net.Socket>((resolve, reject) => {
const conn = net.connect(params.pipeName!, () => resolve(conn));
const conn = net.connect(params.endpoint, () => resolve(conn));
conn.on('error', reject);
});
const transport = new PipeTransport(socket, socket);
Expand Down
20 changes: 10 additions & 10 deletions packages/playwright-core/types/types.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15169,9 +15169,9 @@ 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).
* [browserType.connect(endpoint[, 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).
* [browserType.connect(endpoint[, options])](https://playwright.dev/docs/api/class-browsertype#browser-type-connect).
*
* **Usage**
*
Expand Down Expand Up @@ -15199,9 +15199,9 @@ 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).
* [browserType.connect(endpoint[, 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).
* [browserType.connect(endpoint[, options])](https://playwright.dev/docs/api/class-browsertype#browser-type-connect).
*
* **Usage**
*
Expand All @@ -15222,7 +15222,7 @@ export interface BrowserType<Unused = {}> {
* **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`.
* @param endpoint A Playwright browser websocket endpoint to connect to. You obtain this endpoint via `BrowserServer.wsEndpoint`.
* @param options
*/
connect(wsEndpoint: string, options?: ConnectOptions): Promise<Browser>;
Expand All @@ -15238,7 +15238,7 @@ export interface BrowserType<Unused = {}> {
* **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`.
* @param endpoint A Playwright browser websocket endpoint to connect to. You obtain this endpoint via `BrowserServer.wsEndpoint`.
* @param options
*/
connect(options: ConnectOptions & { wsEndpoint?: string }): Promise<Browser>;
Expand Down Expand Up @@ -15819,7 +15819,7 @@ export interface BrowserType<Unused = {}> {

/**
* Returns the browser app instance. You can connect to it via
* [browserType.connect(wsEndpoint[, options])](https://playwright.dev/docs/api/class-browsertype#browser-type-connect),
* [browserType.connect(endpoint[, options])](https://playwright.dev/docs/api/class-browsertype#browser-type-connect),
* which requires the major/minor client/server version to match (1.2.3 → is compatible with 1.2.x).
*
* **Usage**
Expand Down Expand Up @@ -16818,10 +16818,10 @@ export interface Android {
* This methods attaches Playwright to an existing Android device. Use
* [android.launchServer([options])](https://playwright.dev/docs/api/class-android#android-launch-server) to launch a
* new Android server instance.
* @param wsEndpoint A browser websocket endpoint to connect to.
* @param endpoint A browser websocket endpoint to connect to.
* @param options
*/
connect(wsEndpoint: string, options?: {
connect(endpoint: string, options?: {
/**
* Additional HTTP headers to be sent with web socket connect request. Optional.
*/
Expand Down Expand Up @@ -19103,7 +19103,7 @@ export interface BrowserServer {
* Browser websocket url.
*
* Browser websocket endpoint which can be used as an argument to
* [browserType.connect(wsEndpoint[, options])](https://playwright.dev/docs/api/class-browsertype#browser-type-connect)
* [browserType.connect(endpoint[, options])](https://playwright.dev/docs/api/class-browsertype#browser-type-connect)
* to establish connection to the browser.
*
* Note that if the listen `host` option in `launchServer` options is not specified, localhost will be output anyway,
Expand Down
6 changes: 1 addition & 5 deletions packages/playwright/src/common/fixtures.ts
Original file line number Diff line number Diff line change
Expand Up @@ -228,16 +228,12 @@ export class FixturePool {
return hash.digest('hex');
}

validateFunction(fn: Function, prefix: string, location: Location): 'worker' | 'test' {
let scope: 'worker' | 'test' = 'worker';
validateFunction(fn: Function, prefix: string, location: Location) {
for (const name of fixtureParameterNames(fn, location, e => this._onLoadError(e))) {
const registration = this._registrations.get(name);
if (!registration)
this._addLoadError(`${prefix} has unknown parameter "${name}".`, location);
if (registration?.scope === 'test')
scope = 'test';
}
return scope;
}

resolve(name: string, forFixture?: FixtureRegistration): FixtureRegistration | undefined {
Expand Down
Loading
Loading