mirror of
https://github.com/microsoft/playwright-mcp.git
synced 2025-07-26 16:42:27 +08:00
chore: start trace server (#427)
This commit is contained in:
parent
aa6ac51f92
commit
c2b7fb29de
@ -18,6 +18,8 @@ import { program } from 'commander';
|
|||||||
|
|
||||||
import { startHttpTransport, startStdioTransport } from './transport.js';
|
import { startHttpTransport, startStdioTransport } from './transport.js';
|
||||||
import { resolveCLIConfig } from './config.js';
|
import { resolveCLIConfig } from './config.js';
|
||||||
|
// @ts-ignore
|
||||||
|
import { startTraceViewerServer } from 'playwright-core/lib/server';
|
||||||
|
|
||||||
import type { Connection } from './connection.js';
|
import type { Connection } from './connection.js';
|
||||||
import { packageJSON } from './context.js';
|
import { packageJSON } from './context.js';
|
||||||
@ -59,6 +61,14 @@ program
|
|||||||
startHttpTransport(config, +options.port, options.host, connectionList);
|
startHttpTransport(config, +options.port, options.host, connectionList);
|
||||||
else
|
else
|
||||||
await startStdioTransport(config, connectionList);
|
await startStdioTransport(config, connectionList);
|
||||||
|
|
||||||
|
if (config.saveTrace) {
|
||||||
|
const server = await startTraceViewerServer();
|
||||||
|
const urlPrefix = server.urlPrefix('human-readable');
|
||||||
|
const url = urlPrefix + '/trace/index.html?trace=' + config.browser.launchOptions.tracesDir + '/trace.json';
|
||||||
|
// eslint-disable-next-line no-console
|
||||||
|
console.error('\nTrace viewer listening on ' + url);
|
||||||
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
function setupExitWatchdog(connectionList: Connection[]) {
|
function setupExitWatchdog(connectionList: Connection[]) {
|
||||||
|
@ -140,6 +140,6 @@ export function startHttpTransport(config: FullConfig, port: number, hostname: s
|
|||||||
'If your client supports streamable HTTP, you can use the /mcp endpoint instead.',
|
'If your client supports streamable HTTP, you can use the /mcp endpoint instead.',
|
||||||
].join('\n');
|
].join('\n');
|
||||||
// eslint-disable-next-line no-console
|
// eslint-disable-next-line no-console
|
||||||
console.log(message);
|
console.error(message);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
@ -35,10 +35,10 @@ const test = baseTest.extend<{ serverEndpoint: string }>({
|
|||||||
serverEndpoint: async ({}, use) => {
|
serverEndpoint: async ({}, use) => {
|
||||||
const cp = spawn('node', [path.join(path.dirname(__filename), '../cli.js'), '--port', '0'], { stdio: 'pipe' });
|
const cp = spawn('node', [path.join(path.dirname(__filename), '../cli.js'), '--port', '0'], { stdio: 'pipe' });
|
||||||
try {
|
try {
|
||||||
let stdout = '';
|
let stderr = '';
|
||||||
const url = await new Promise<string>(resolve => cp.stdout?.on('data', data => {
|
const url = await new Promise<string>(resolve => cp.stderr?.on('data', data => {
|
||||||
stdout += data.toString();
|
stderr += data.toString();
|
||||||
const match = stdout.match(/Listening on (http:\/\/.*)/);
|
const match = stderr.match(/Listening on (http:\/\/.*)/);
|
||||||
if (match)
|
if (match)
|
||||||
resolve(match[1]);
|
resolve(match[1]);
|
||||||
}));
|
}));
|
||||||
|
Loading…
x
Reference in New Issue
Block a user