Skip to content

Commit c924c49

Browse files
committed
chore: try snapshot
1 parent ca57104 commit c924c49

19 files changed

Lines changed: 35327 additions & 93 deletions

.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 & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -372,7 +372,8 @@ If you run into any issues, checkout our [troubleshooting guide](./docs/troubles
372372
- **Emulation** (2 tools)
373373
- [`emulate`](docs/tool-reference.md#emulate)
374374
- [`resize_page`](docs/tool-reference.md#resize_page)
375-
- **Performance** (3 tools)
375+
- **Performance** (4 tools)
376+
- [`lighthouse_audit`](docs/tool-reference.md#lighthouse_audit)
376377
- [`performance_analyze_insight`](docs/tool-reference.md#performance_analyze_insight)
377378
- [`performance_start_trace`](docs/tool-reference.md#performance_start_trace)
378379
- [`performance_stop_trace`](docs/tool-reference.md#performance_stop_trace)

docs/tool-reference.md

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,8 @@
2121
- **[Emulation](#emulation)** (2 tools)
2222
- [`emulate`](#emulate)
2323
- [`resize_page`](#resize_page)
24-
- **[Performance](#performance)** (3 tools)
24+
- **[Performance](#performance)** (4 tools)
25+
- [`lighthouse_audit`](#lighthouse_audit)
2526
- [`performance_analyze_insight`](#performance_analyze_insight)
2627
- [`performance_start_trace`](#performance_start_trace)
2728
- [`performance_stop_trace`](#performance_stop_trace)
@@ -228,6 +229,20 @@
228229

229230
## Performance
230231

232+
### `lighthouse_audit`
233+
234+
**Description:** Runs a Lighthouse audit on the currently selected page.
235+
236+
**Parameters:**
237+
238+
- **categories** (array) _(optional)_: The categories to audit. Defaults to all available categories.
239+
- **device** (enum: "desktop", "mobile") _(optional)_: The device to [`emulate`](#emulate). "desktop" is the default. "mobile" emulates a mobile device.
240+
- **formats** (array) _(optional)_: Report formats to produce.
241+
- **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.
242+
- **outputDirPath** (string) _(optional)_: The directory to output the reports to. If not provided, temporary files will be created.
243+
244+
---
245+
231246
### `performance_analyze_insight`
232247

233248
**Description:** Provides more detailed information on a specific Performance Insight of an insight set that was highlighted in the results of a trace recording.

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: 4 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,11 @@ export default [
260261
return true;
261262
}
262263

263-
const existingExternals = ['./bidi.js', '../bidi/bidi.js'];
264+
const existingExternals = ['./bidi.js', '../bidi/bidi.js', './lighthouse-devtools-mcp-bundle.js'];
265+
264266
if (existingExternals.includes(source)) {
265267
return true;
266268
}
267-
268269
return false;
269270
},
270271
),

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)