mirror of
https://github.com/microsoft/playwright-mcp.git
synced 2025-07-26 08:32:26 +08:00
chore(extension): use free port (#735)
This commit is contained in:
parent
da8a244f33
commit
c72d0320f4
@ -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, () => {
|
||||
|
@ -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()}.`);
|
||||
|
@ -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();
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user