chore: allow passing cdp endpoint (#86)
Fixes https://github.com/microsoft/playwright-mcp/issues/84
This commit is contained in:
@@ -313,3 +313,21 @@ test('sse transport', async () => {
|
||||
cp.kill();
|
||||
}
|
||||
});
|
||||
|
||||
test('cdp server', async ({ cdpEndpoint, startClient }) => {
|
||||
const client = await startClient({ args: [`--cdp-endpoint=${cdpEndpoint}`] });
|
||||
expect(await client.callTool({
|
||||
name: 'browser_navigate',
|
||||
arguments: {
|
||||
url: 'data:text/html,<html><title>Title</title><body>Hello, world!</body></html>',
|
||||
},
|
||||
})).toHaveTextContent(`
|
||||
- Page URL: data:text/html,<html><title>Title</title><body>Hello, world!</body></html>
|
||||
- Page Title: Title
|
||||
- Page Snapshot
|
||||
\`\`\`yaml
|
||||
- document [ref=s1e2]: Hello, world!
|
||||
\`\`\`
|
||||
`
|
||||
);
|
||||
});
|
||||
|
||||
@@ -24,8 +24,9 @@ import { Client } from '@modelcontextprotocol/sdk/client/index.js';
|
||||
type Fixtures = {
|
||||
client: Client;
|
||||
visionClient: Client;
|
||||
startClient: (options?: { env?: NodeJS.ProcessEnv, vision?: boolean }) => Promise<Client>;
|
||||
startClient: (options?: { args?: string[], vision?: boolean }) => Promise<Client>;
|
||||
wsEndpoint: string;
|
||||
cdpEndpoint: string;
|
||||
};
|
||||
|
||||
export const test = baseTest.extend<Fixtures>({
|
||||
@@ -46,6 +47,8 @@ export const test = baseTest.extend<Fixtures>({
|
||||
const args = ['--headless', '--user-data-dir', userDataDir];
|
||||
if (options?.vision)
|
||||
args.push('--vision');
|
||||
if (options?.args)
|
||||
args.push(...options.args);
|
||||
const transport = new StdioClientTransport({
|
||||
command: 'node',
|
||||
args: [path.join(__dirname, '../cli.js'), ...args],
|
||||
@@ -64,6 +67,15 @@ export const test = baseTest.extend<Fixtures>({
|
||||
await use(browserServer.wsEndpoint());
|
||||
await browserServer.close();
|
||||
},
|
||||
|
||||
cdpEndpoint: async ({ }, use, testInfo) => {
|
||||
const port = 3200 + (+process.env.TEST_PARALLEL_INDEX!);
|
||||
const browser = await chromium.launchPersistentContext(testInfo.outputPath('user-data-dir'), {
|
||||
args: [`--remote-debugging-port=${port}`],
|
||||
});
|
||||
await use(`http://localhost:${port}`);
|
||||
await browser.close();
|
||||
},
|
||||
});
|
||||
|
||||
type Response = Awaited<ReturnType<Client['callTool']>>;
|
||||
|
||||
Reference in New Issue
Block a user