mirror of
https://github.com/microsoft/playwright-mcp.git
synced 2026-02-01 08:13:38 +00:00
Compare commits
1 Commits
test
...
fix-npm-pu
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
4cebc50b19 |
@@ -51,7 +51,6 @@ FROM base
|
|||||||
ARG PLAYWRIGHT_BROWSERS_PATH
|
ARG PLAYWRIGHT_BROWSERS_PATH
|
||||||
ARG USERNAME=node
|
ARG USERNAME=node
|
||||||
ENV NODE_ENV=production
|
ENV NODE_ENV=production
|
||||||
ENV PLAYWRIGHT_MCP_OUTPUT_DIR=/tmp/playwright-output
|
|
||||||
|
|
||||||
# Set the correct ownership for the runtime user on production `node_modules`
|
# Set the correct ownership for the runtime user on production `node_modules`
|
||||||
RUN chown -R ${USERNAME}:${USERNAME} node_modules
|
RUN chown -R ${USERNAME}:${USERNAME} node_modules
|
||||||
|
|||||||
@@ -22,8 +22,7 @@
|
|||||||
"ctest": "playwright test --project=chrome",
|
"ctest": "playwright test --project=chrome",
|
||||||
"ftest": "playwright test --project=firefox",
|
"ftest": "playwright test --project=firefox",
|
||||||
"wtest": "playwright test --project=webkit",
|
"wtest": "playwright test --project=webkit",
|
||||||
"dtest": "MCP_IN_DOCKER=1 playwright test --project=chromium-docker",
|
"dtest": "MCP_IN_DOCKER=1 playwright test --project=chromium-docker"
|
||||||
"npm-publish": "npm run clean && npm run test && npm publish"
|
|
||||||
},
|
},
|
||||||
"exports": {
|
"exports": {
|
||||||
"./package.json": "./package.json",
|
"./package.json": "./package.json",
|
||||||
|
|||||||
115
test.mjs
115
test.mjs
@@ -1,115 +0,0 @@
|
|||||||
/**
|
|
||||||
* Copyright (c) Microsoft Corporation.
|
|
||||||
*
|
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
||||||
* you may not use this file except in compliance with the License.
|
|
||||||
* You may obtain a copy of the License at
|
|
||||||
*
|
|
||||||
* http://www.apache.org/licenses/LICENSE-2.0
|
|
||||||
*
|
|
||||||
* Unless required by applicable law or agreed to in writing, software
|
|
||||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
||||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
||||||
* See the License for the specific language governing permissions and
|
|
||||||
* limitations under the License.
|
|
||||||
*/
|
|
||||||
|
|
||||||
import { Client } from '@modelcontextprotocol/sdk/client/index.js';
|
|
||||||
import { StdioClientTransport } from '@modelcontextprotocol/sdk/client/stdio.js';
|
|
||||||
import { StreamableHTTPClientTransport } from '@modelcontextprotocol/sdk/client/streamableHttp.js';
|
|
||||||
import { ListRootsRequestSchema, PingRequestSchema } from '@modelcontextprotocol/sdk/types.js';
|
|
||||||
|
|
||||||
export async function connectMCP() {
|
|
||||||
// const transport = new StreamableHTTPClientTransport(new URL('http://localhost:4242/mcp'));
|
|
||||||
|
|
||||||
const transport = new StdioClientTransport({
|
|
||||||
command: 'node',
|
|
||||||
env: process.env,
|
|
||||||
args: [
|
|
||||||
'/Users/yurys/playwright/packages/playwright/cli.js',
|
|
||||||
'run-mcp-server',
|
|
||||||
'--browser=chrome-canary',
|
|
||||||
'--extension',
|
|
||||||
// '--browser=chromium',
|
|
||||||
// '--no-sandbox',
|
|
||||||
// '--isolated',
|
|
||||||
],
|
|
||||||
stderr: 'inherit',
|
|
||||||
});
|
|
||||||
|
|
||||||
|
|
||||||
console.error('will create client');
|
|
||||||
const client = new Client({ name: 'Visual Studio Code', version: '1.0.0' });
|
|
||||||
client.setRequestHandler(PingRequestSchema, async () => ({}));
|
|
||||||
|
|
||||||
console.error('Will connect');
|
|
||||||
try {
|
|
||||||
await client.connect(transport);
|
|
||||||
} catch (error) {
|
|
||||||
console.error('Connection error:', error);
|
|
||||||
}
|
|
||||||
console.error('Connected');
|
|
||||||
|
|
||||||
// const tools = await client.listTools();
|
|
||||||
// console.log('Available tools:', tools.tools.length);
|
|
||||||
|
|
||||||
// await client.ping();
|
|
||||||
// console.error('Pinged');
|
|
||||||
|
|
||||||
{
|
|
||||||
const response = await client.callTool({
|
|
||||||
name: 'browser_navigate',
|
|
||||||
arguments: {
|
|
||||||
url: 'https://amazon.com/'
|
|
||||||
}
|
|
||||||
});
|
|
||||||
console.log('Navigated to Amazon', response.isError ? 'error' : '', response.error ? response.error : '');
|
|
||||||
}
|
|
||||||
|
|
||||||
// const r = await client.callTool({
|
|
||||||
// name: 'browser_connect',
|
|
||||||
// arguments: {
|
|
||||||
// name: 'extension'
|
|
||||||
// }
|
|
||||||
// });
|
|
||||||
// console.log('Connected to extension', r.isError ? 'error' : '', r.content);
|
|
||||||
|
|
||||||
const response = await client.callTool({
|
|
||||||
name: 'browser_navigate',
|
|
||||||
arguments: {
|
|
||||||
url: 'https://google.com/'
|
|
||||||
}
|
|
||||||
});
|
|
||||||
console.log('Navigated to Google', response.isError ? 'error' : '', response.isError ? response : '');
|
|
||||||
|
|
||||||
if (response.isError)
|
|
||||||
return;
|
|
||||||
|
|
||||||
const response2 = await client.callTool({
|
|
||||||
name: 'browser_type',
|
|
||||||
arguments: {
|
|
||||||
text: 'Browser MCP',
|
|
||||||
submit: true,
|
|
||||||
element: 'combobox "Search" [active] [ref=e44]',
|
|
||||||
ref: 'e44',
|
|
||||||
}
|
|
||||||
});
|
|
||||||
console.log('Typed text', response2.isError ? response2.content : '');
|
|
||||||
|
|
||||||
// console.log('Closing browser...');
|
|
||||||
// const response3 = await client.callTool({
|
|
||||||
// name: 'browser_close',
|
|
||||||
// arguments: {}
|
|
||||||
// });
|
|
||||||
// console.log('Closed browser');
|
|
||||||
// console.log(response3.isError ? 'error' : '', response3.error ? response3.error : '');
|
|
||||||
|
|
||||||
|
|
||||||
// await new Promise(resolve => setTimeout(resolve, 5_000));
|
|
||||||
|
|
||||||
// await transport.terminateSession();
|
|
||||||
await client.close();
|
|
||||||
console.log('Closed MCP client');
|
|
||||||
}
|
|
||||||
|
|
||||||
void connectMCP();
|
|
||||||
Reference in New Issue
Block a user