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
6 changes: 2 additions & 4 deletions packages/playwright-core/src/cli/daemon/program.ts
Original file line number Diff line number Diff line change
Expand Up @@ -53,12 +53,10 @@ export function decorateCLICommand(command: Command, version: string) {
const socketPath = await startCliDaemonServer(sessionName, browserContext, mcpConfig, clientInfo, { persistent, exitOnClose: true });
console.log(`### Success\nDaemon listening on ${socketPath}`);
console.log('<EOF>');
try {

if (!(browser as any)._connection.isRemote()) {
await (browser as any)._startServer(sessionName, { workspaceDir: clientInfo.workspaceDir });
browserContext.on('close', () => (browser as any)._stopServer().catch(() => {}));
} catch (error) {
if (!error.message.includes('Server is already running'))
throw error;
}
} catch (error) {
const message = process.env.PWDEBUGIMPL ? (error as Error).stack || (error as Error).message : (error as Error).message;
Expand Down
4 changes: 2 additions & 2 deletions packages/playwright-core/src/client/browser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ import { mkdirIfNeeded } from './fileUtils';

import type { BrowserType } from './browserType';
import type { Page } from './page';
import type { BrowserContextOptions, LaunchOptions, Logger } from './types';
import type { BrowserContextOptions, LaunchOptions, Logger, StartServerOptions } from './types';
import type * as api from '../../types/types';
import type * as channels from '@protocol/channels';

Expand Down Expand Up @@ -130,7 +130,7 @@ export class Browser extends ChannelOwner<channels.BrowserChannel> implements ap
return this._initializer.version;
}

async _startServer(title: string, options: { wsPath?: string, workspaceDir?: string } = {}): Promise<{ wsEndpoint?: string, pipeName?: string }> {
async _startServer(title: string, options: StartServerOptions = {}): Promise<{ wsEndpoint?: string, pipeName?: string }> {
return await this._channel.startServer({ title, ...options });
}

Expand Down
8 changes: 8 additions & 0 deletions packages/playwright-core/src/client/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,14 @@ export type LaunchAndroidServerOptions = {
wsPath?: string,
};

export type StartServerOptions = {
host?: string,
port?: number,
wsPath?: string,
workspaceDir?: string,
metadata?: Record<string, any>,
};

export type SelectorEngine = {
/**
* Returns the first element matching given selector in the root's subtree.
Expand Down
3 changes: 3 additions & 0 deletions packages/playwright-core/src/protocol/validator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -652,8 +652,11 @@ scheme.BrowserContextEvent = tObject({
scheme.BrowserCloseEvent = tOptional(tObject({}));
scheme.BrowserStartServerParams = tObject({
title: tString,
host: tOptional(tString),
port: tOptional(tInt),
wsPath: tOptional(tString),
workspaceDir: tOptional(tString),
metadata: tOptional(tAny),
});
scheme.BrowserStartServerResult = tObject({
wsEndpoint: tOptional(tString),
Expand Down
7 changes: 4 additions & 3 deletions packages/playwright-core/src/server/browser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -174,7 +174,7 @@ export abstract class Browser extends SdkObject {
return video?.artifact;
}

async startServer(title: string, options: { workspaceDir?: string, wsPath?: string, pipeName?: string }): Promise<{ wsEndpoint?: string, pipeName?: string }> {
async startServer(title: string, options: channels.BrowserStartServerOptions): Promise<{ wsEndpoint?: string, pipeName?: string }> {
return await this._server.start(title, options);
}

Expand Down Expand Up @@ -219,7 +219,7 @@ export class BrowserServer {
this._browser = browser;
}

async start(title: string, options: { workspaceDir?: string, wsPath?: string }): Promise<{ wsEndpoint?: string, pipeName?: string }> {
async start(title: string, options: channels.BrowserStartServerOptions): Promise<{ wsEndpoint?: string, pipeName?: string }> {
if (this._isStarted)
throw new Error(`Server is already started.`);
this._isStarted = true;
Expand All @@ -233,7 +233,7 @@ export class BrowserServer {
if (options.wsPath) {
const path = options.wsPath.startsWith('/') ? options.wsPath : `/${options.wsPath}`;
this._wsServer = new PlaywrightWebSocketServer(this._browser, path);
result.wsEndpoint = await this._wsServer.listen(0, 'localhost', path);
result.wsEndpoint = await this._wsServer.listen(options.port ?? 0, options.host ?? 'localhost', path);
}

const browserInfo: BrowserInfo = {
Expand All @@ -247,6 +247,7 @@ export class BrowserServer {
wsEndpoint: result.wsEndpoint,
pipeName: result.pipeName,
workspaceDir: options.workspaceDir,
metadata: options.metadata,
});
return result;
}
Expand Down
1 change: 1 addition & 0 deletions packages/playwright-core/src/serverRegistry.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ export type EndpointInfo = {
wsEndpoint?: string;
pipeName?: string;
workspaceDir?: string;
metadata?: Record<string, any>;
};

export type BrowserDescriptor = EndpointInfo & {
Expand Down
6 changes: 6 additions & 0 deletions packages/protocol/src/channels.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1181,12 +1181,18 @@ export type BrowserContextEvent = {
export type BrowserCloseEvent = {};
export type BrowserStartServerParams = {
title: string,
host?: string,
port?: number,
wsPath?: string,
workspaceDir?: string,
metadata?: any,
};
export type BrowserStartServerOptions = {
host?: string,
port?: number,
wsPath?: string,
workspaceDir?: string,
metadata?: any,
};
export type BrowserStartServerResult = {
wsEndpoint?: string,
Expand Down
3 changes: 3 additions & 0 deletions packages/protocol/src/protocol.yml
Original file line number Diff line number Diff line change
Expand Up @@ -1043,8 +1043,11 @@ Browser:
title: Start server
parameters:
title: string
host: string?
port: int?
wsPath: string?
workspaceDir: string?
metadata: json?
returns:
wsEndpoint: string?
pipeName: string?
Expand Down
Loading