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

Commit 55a3355

Browse files
committed
chore: try snapshot
1 parent ca57104 commit 55a3355

20 files changed

+55385
-92
lines changed

.github/workflows/run-tests.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ jobs:
4444
- name: Build
4545
run: npm run bundle
4646
env:
47-
NODE_OPTIONS: '--max_old_space_size=4096'
47+
NODE_OPTIONS: '--max_old_space_size=8192'
4848

4949
- name: Set up Node.js
5050
uses: actions/setup-node@6044e13b5dc448c55e2357c09f80417699197238 # v6.2.0

README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -353,6 +353,8 @@ If you run into any issues, checkout our [troubleshooting guide](./docs/troubles
353353

354354
<!-- BEGIN AUTO GENERATED TOOLS -->
355355

356+
- **Audits** (1 tools)
357+
- [`lighthouse_audit`](docs/tool-reference.md#lighthouse_audit)
356358
- **Input automation** (8 tools)
357359
- [`click`](docs/tool-reference.md#click)
358360
- [`drag`](docs/tool-reference.md#drag)

docs/tool-reference.md

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22

33
# Chrome DevTools MCP Tool Reference
44

5+
- **[Audits](#audits)** (1 tools)
6+
- [`lighthouse_audit`](#lighthouse_audit)
57
- **[Input automation](#input-automation)** (8 tools)
68
- [`click`](#click)
79
- [`drag`](#drag)
@@ -35,6 +37,22 @@
3537
- [`take_screenshot`](#take_screenshot)
3638
- [`take_snapshot`](#take_snapshot)
3739

40+
## Audits
41+
42+
### `lighthouse_audit`
43+
44+
**Description:** Runs a Lighthouse audit on the currently selected page.
45+
46+
**Parameters:**
47+
48+
- **categories** (array) _(optional)_: The categories to audit. Defaults to all available categories.
49+
- **device** (enum: "desktop", "mobile") _(optional)_: The device to [`emulate`](#emulate). "desktop" is the default. "mobile" emulates a mobile device.
50+
- **formats** (array) _(optional)_: Report formats to produce.
51+
- **mode** (enum: "navigation", "snapshot") _(optional)_: The mode to run Lighthouse in. "navigation" is the default and will reload the current page. "snapshot" analyzes the page in its current state.
52+
- **outputDirPath** (string) _(optional)_: The directory to output the reports to. If not provided, temporary files will be created.
53+
54+
---
55+
3856
## Input automation
3957

4058
### `click`

eslint.config.mjs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,11 @@ import tseslint from 'typescript-eslint';
1414
import localPlugin from './scripts/eslint_rules/local-plugin.js';
1515

1616
export default defineConfig([
17-
globalIgnores(['**/node_modules', '**/build/']),
17+
globalIgnores([
18+
'**/node_modules',
19+
'**/build/',
20+
'src/third_party/lighthouse-devtools-mcp-bundle.js',
21+
]),
1822
importPlugin.flatConfigs.typescript,
1923
{
2024
languageOptions: {

package-lock.json

Lines changed: 5 additions & 23 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@
6161
"eslint-import-resolver-typescript": "^4.4.4",
6262
"eslint-plugin-import": "^2.32.0",
6363
"globals": "^17.0.0",
64-
"lighthouse": "^13.0.1",
64+
"lighthouse": "13.0.2",
6565
"prettier": "^3.6.2",
6666
"puppeteer": "24.37.2",
6767
"rollup": "4.57.1",

rollup.config.mjs

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,8 @@ function listBundledDeps() {
107107
Object.entries(devDependencies).filter(
108108
([name]) =>
109109
aggregatedStats.bundledPackages.has(name) ||
110-
name === 'chrome-devtools-frontend',
110+
name === 'chrome-devtools-frontend' ||
111+
name === 'lighthouse',
111112
),
112113
);
113114

@@ -260,11 +261,15 @@ export default [
260261
return true;
261262
}
262263

263-
const existingExternals = ['./bidi.js', '../bidi/bidi.js'];
264+
const existingExternals = [
265+
'./bidi.js',
266+
'../bidi/bidi.js',
267+
'./lighthouse-devtools-mcp-bundle.js',
268+
];
269+
264270
if (existingExternals.includes(source)) {
265271
return true;
266272
}
267-
268273
return false;
269274
},
270275
),

scripts/prepare.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,9 @@ function removeConflictingGlobalDeclaration(): void {
2727
projectRoot,
2828
'node_modules/@paulirish/trace_engine/models/trace/ModelImpl.d.ts',
2929
);
30-
console.log('Removing conflicting global declaration from @paulirish/trace_engine...');
30+
console.log(
31+
'Removing conflicting global declaration from @paulirish/trace_engine...',
32+
);
3133
const content = readFileSync(filePath, 'utf-8');
3234
// Remove the declare global block using regex
3335
// Matches: declare global { ... interface HTMLElementEventMap { ... } ... }

src/McpContext.ts

Lines changed: 9 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -93,18 +93,6 @@ function getNetworkMultiplierFromString(condition: string | null): number {
9393
return 1;
9494
}
9595

96-
function getExtensionFromMimeType(mimeType: string) {
97-
switch (mimeType) {
98-
case 'image/png':
99-
return 'png';
100-
case 'image/jpeg':
101-
return 'jpeg';
102-
case 'image/webp':
103-
return 'webp';
104-
}
105-
throw new Error(`No mapping for Mime type ${mimeType}.`);
106-
}
107-
10896
export class McpContext implements Context {
10997
browser: Browser;
11098
logger: Debugger;
@@ -677,22 +665,19 @@ export class McpContext implements Context {
677665

678666
async saveTemporaryFile(
679667
data: Uint8Array<ArrayBufferLike>,
680-
mimeType: 'image/png' | 'image/jpeg' | 'image/webp',
681-
): Promise<{filename: string}> {
668+
filename: string,
669+
): Promise<{filepath: string}> {
682670
try {
683671
const dir = await fs.mkdtemp(
684672
path.join(os.tmpdir(), 'chrome-devtools-mcp-'),
685673
);
686674

687-
const filename = path.join(
688-
dir,
689-
`screenshot.${getExtensionFromMimeType(mimeType)}`,
690-
);
691-
await fs.writeFile(filename, data);
692-
return {filename};
675+
const filepath = path.join(dir, filename);
676+
await fs.writeFile(filepath, data);
677+
return {filepath};
693678
} catch (err) {
694679
this.logger(err);
695-
throw new Error('Could not save a screenshot to a file', {cause: err});
680+
throw new Error('Could not save a file', {cause: err});
696681
}
697682
}
698683
async saveFile(
@@ -701,11 +686,12 @@ export class McpContext implements Context {
701686
): Promise<{filename: string}> {
702687
try {
703688
const filePath = path.resolve(filename);
689+
await fs.mkdir(path.dirname(filePath), {recursive: true});
704690
await fs.writeFile(filePath, data);
705-
return {filename};
691+
return {filename: filePath};
706692
} catch (err) {
707693
this.logger(err);
708-
throw new Error('Could not save a screenshot to a file', {cause: err});
694+
throw new Error('Could not save a file', {cause: err});
709695
}
710696
}
711697

0 commit comments

Comments
 (0)