feat(network): implement listing network requests (#247)

Fixes: https://github.com/microsoft/playwright-mcp/issues/242
This commit is contained in:
Pavel Feldman
2025-04-22 16:04:25 -07:00
committed by GitHub
parent c80f7cf222
commit 1bc3c761de
11 changed files with 401 additions and 4 deletions

View File

@@ -21,6 +21,7 @@ import { test as baseTest, expect as baseExpect } from '@playwright/test';
import { StdioClientTransport } from '@modelcontextprotocol/sdk/client/stdio.js';
import { Client } from '@modelcontextprotocol/sdk/client/index.js';
import { spawn } from 'child_process';
import { TestServer } from './testserver';
type TestFixtures = {
client: Client;
@@ -28,11 +29,14 @@ type TestFixtures = {
startClient: (options?: { args?: string[] }) => Promise<Client>;
wsEndpoint: string;
cdpEndpoint: string;
server: TestServer;
httpsServer: TestServer;
};
type WorkerFixtures = {
mcpHeadless: boolean;
mcpBrowser: string | undefined;
_workerServers: { server: TestServer, httpsServer: TestServer };
};
export const test = baseTest.extend<TestFixtures, WorkerFixtures>({
@@ -103,7 +107,32 @@ export const test = baseTest.extend<TestFixtures, WorkerFixtures>({
await use(headless);
}, { scope: 'worker' }],
mcpBrowser: ['chromium', { option: true, scope: 'worker' }],
mcpBrowser: ['chrome', { option: true, scope: 'worker' }],
_workerServers: [async ({}, use, workerInfo) => {
const port = 8907 + workerInfo.workerIndex * 4;
const server = await TestServer.create(port);
const httpsPort = port + 1;
const httpsServer = await TestServer.createHTTPS(httpsPort);
await use({ server, httpsServer });
await Promise.all([
server.stop(),
httpsServer.stop(),
]);
}, { scope: 'worker' }],
server: async ({ _workerServers }, use) => {
_workerServers.server.reset();
await use(_workerServers.server);
},
httpsServer: async ({ _workerServers }, use) => {
_workerServers.httpsServer.reset();
await use(_workerServers.httpsServer);
},
});
type Response = Awaited<ReturnType<Client['callTool']>>;