chore(extension): use free port (#735)

This commit is contained in:
Yury Semikhatsky 2025-07-24 10:25:13 -07:00 committed by GitHub
parent da8a244f33
commit c72d0320f4
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 5 additions and 5 deletions

View File

@ -217,7 +217,7 @@ async function injectCdpPort(browserConfig: FullConfig['browser']) {
(browserConfig.launchOptions as any).cdpPort = await findFreePort();
}
async function findFreePort() {
async function findFreePort(): Promise<number> {
return new Promise((resolve, reject) => {
const server = net.createServer();
server.listen(0, () => {

View File

@ -28,10 +28,10 @@ import { WebSocket, WebSocketServer } from 'ws';
import debug from 'debug';
import * as playwright from 'playwright';
import { httpAddressToString, startHttpServer } from '../transport.js';
import { BrowserContextFactory } from '../browserContextFactory.js';
// @ts-ignore
const { registry } = await import('playwright-core/lib/server/registry/index');
import type { BrowserContextFactory } from '../browserContextFactory.js';
import type websocket from 'ws';
const debugLogger = debug('pw:mcp:relay');
@ -324,8 +324,8 @@ class ExtensionContextFactory implements BrowserContextFactory {
}
}
export async function startCDPRelayServer(port: number, browserChannel: string) {
const httpServer = await startHttpServer({ port });
export async function startCDPRelayServer(browserChannel: string) {
const httpServer = await startHttpServer({});
const cdpRelayServer = new CDPRelayServer(httpServer, browserChannel);
process.on('exit', () => cdpRelayServer.stop());
debugLogger(`CDP relay server started, extension endpoint: ${cdpRelayServer.extensionEndpoint()}.`);

View File

@ -22,7 +22,7 @@ import { filteredTools } from '../tools.js';
import type { FullConfig } from '../config.js';
export async function runWithExtension(config: FullConfig) {
const contextFactory = await startCDPRelayServer(9225, config.browser.launchOptions.channel || 'chrome');
const contextFactory = await startCDPRelayServer(config.browser.launchOptions.channel || 'chrome');
const server = new Server(config, filteredTools(config), contextFactory);
server.setupExitWatchdog();