豆豆友情提示:这是一个非官方 GitHub 代理镜像,主要用于网络测试或访问加速。请勿在此进行登录、注册或处理任何敏感信息。进行这些操作请务必访问官方网站 github.com。 Raw 内容也通过此代理提供。
Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 18 additions & 18 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@
"mcpName": "io.github.ChromeDevTools/chrome-devtools-mcp",
"devDependencies": {
"@eslint/js": "^9.35.0",
"@modelcontextprotocol/sdk": "1.20.1",
"@modelcontextprotocol/sdk": "1.20.2",
"@rollup/plugin-commonjs": "^28.0.8",
"@rollup/plugin-json": "^6.1.0",
"@rollup/plugin-node-resolve": "^16.0.3",
Expand All @@ -59,7 +59,7 @@
"eslint-plugin-import": "^2.32.0",
"globals": "^16.4.0",
"prettier": "^3.6.2",
"puppeteer": "24.26.0",
"puppeteer": "24.26.1",
"rollup": "4.52.5",
"rollup-plugin-cleanup": "^3.2.1",
"rollup-plugin-license": "^3.6.0",
Expand Down
45 changes: 45 additions & 0 deletions tests/McpResponse.test.js.snapshot
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
exports[`McpResponse > returns correctly formatted snapshot for a simple tree 1`] = `
# test response
## Page content
uid=1_0 RootWebArea "My test page" url="about:blank"
uid=1_1 button "Click me" focusable focused
uid=1_2 textbox value="Input"

`;

exports[`McpResponse > returns values for textboxes 1`] = `
# test response
## Page content
uid=1_0 RootWebArea "My test page" url="about:blank"
uid=1_1 StaticText "username"
uid=1_2 textbox "username" focusable focused value="mcp"

`;

exports[`McpResponse > returns verbose snapshot 1`] = `
# test response
## Page content
uid=1_0 RootWebArea "My test page" url="about:blank"
uid=1_1 ignored
uid=1_2 ignored
uid=1_3 complementary
uid=1_4 StaticText "test"
uid=1_5 InlineTextBox "test"

`;

exports[`McpResponse > saves snapshot to file 1`] = `
# test response
## Page content
Saved snapshot to <file>
`;

exports[`McpResponse > saves snapshot to file 2`] = `
uid=1_0 RootWebArea "My test page" url="about:blank"
uid=1_1 ignored
uid=1_2 ignored
uid=1_3 complementary
uid=1_4 StaticText "test"
uid=1_5 InlineTextBox "test"

`;
69 changes: 17 additions & 52 deletions tests/McpResponse.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,13 @@ import {tmpdir} from 'node:os';
import {join} from 'node:path';
import {describe, it} from 'node:test';

import {getMockRequest, getMockResponse, html, withBrowser} from './utils.js';
import {
getMockRequest,
getMockResponse,
html,
stabilizeResponseOutput,
withBrowser,
} from './utils.js';

describe('McpResponse', () => {
it('list pages', async () => {
Expand Down Expand Up @@ -51,7 +57,7 @@ Testing 2`,
});
});

it('returns correctly formatted snapshot for a simple tree', async () => {
it('returns correctly formatted snapshot for a simple tree', async t => {
await withBrowser(async (response, context) => {
const page = context.getSelectedPage();
await page.setContent(
Expand All @@ -65,19 +71,11 @@ Testing 2`,
response.includeSnapshot();
const result = await response.handle('test', context);
assert.equal(result[0].type, 'text');
assert.strictEqual(
result[0].text,
`# test response
## Page content
uid=1_0 RootWebArea "My test page"
uid=1_1 button "Click me" focusable focused
uid=1_2 textbox value="Input"
`,
);
t.assert.snapshot?.(result[0].text);
});
});

it('returns values for textboxes', async () => {
it('returns values for textboxes', async t => {
await withBrowser(async (response, context) => {
const page = context.getSelectedPage();
await page.setContent(
Expand All @@ -91,19 +89,11 @@ uid=1_0 RootWebArea "My test page"
response.includeSnapshot();
const result = await response.handle('test', context);
assert.equal(result[0].type, 'text');
assert.strictEqual(
result[0].text,
`# test response
## Page content
uid=1_0 RootWebArea "My test page"
uid=1_1 StaticText "username"
uid=1_2 textbox "username" focusable focused value="mcp"
`,
);
t.assert.snapshot?.(result[0].text);
});
});

it('returns verbose snapshot', async () => {
it('returns verbose snapshot', async t => {
await withBrowser(async (response, context) => {
const page = context.getSelectedPage();
await page.setContent(html`<aside>test</aside>`);
Expand All @@ -112,22 +102,11 @@ uid=1_0 RootWebArea "My test page"
});
const result = await response.handle('test', context);
assert.equal(result[0].type, 'text');
assert.strictEqual(
result[0].text,
`# test response
## Page content
uid=1_0 RootWebArea "My test page"
uid=1_1 ignored
uid=1_2 ignored
uid=1_3 complementary
uid=1_4 StaticText "test"
uid=1_5 InlineTextBox "test"
`,
);
t.assert.snapshot?.(result[0].text);
});
});

it('saves snapshot to file', async () => {
it('saves snapshot to file', async t => {
const filePath = join(tmpdir(), 'test-screenshot.png');
try {
await withBrowser(async (response, context) => {
Expand All @@ -139,25 +118,10 @@ uid=1_0 RootWebArea "My test page"
});
const result = await response.handle('test', context);
assert.equal(result[0].type, 'text');
console.log(result[0].text);
assert.strictEqual(
result[0].text,
`# test response
## Page content
Saved snapshot to ${filePath}.`,
);
t.assert.snapshot?.(stabilizeResponseOutput(result[0].text));
});
const content = await readFile(filePath, 'utf-8');
assert.strictEqual(
content,
`uid=1_0 RootWebArea "My test page"
uid=1_1 ignored
uid=1_2 ignored
uid=1_3 complementary
uid=1_4 StaticText "test"
uid=1_5 InlineTextBox "test"
`,
);
t.assert.snapshot?.(stabilizeResponseOutput(content));
} finally {
await rm(filePath, {force: true});
}
Expand Down Expand Up @@ -492,6 +456,7 @@ No requests found.`,
];
};
const result = await response.handle('test', context);

assert.strictEqual(
result[0].text,
`# test response
Expand Down
3 changes: 3 additions & 0 deletions tests/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -170,5 +170,8 @@ export function stabilizeResponseOutput(text: unknown) {
// sec-ch-ua-platform:"Linux"
const chUaPlatformRegEx = /sec-ch-ua-platform:"[a-zA-Z]*"/g;
output = output.replaceAll(chUaPlatformRegEx, 'sec-ch-ua-platform:"<os>"');

const savedSnapshot = /Saved snapshot to (.*)/g;
output = output.replaceAll(savedSnapshot, 'Saved snapshot to <file>');
return output;
}