Skip to content

Chrome DevTools for coding agents

fix: round lighthouse category scores and show unscored categories as n/a (#2924)

yulunz70076808cd94
diff --git a/src/McpResponse.ts b/src/McpResponse.ts
index 4b20b89f..b9a244ea 100644
--- a/src/McpResponse.ts
+++ b/src/McpResponse.ts
@@ -1174,9 +1174,11 @@ Call ${handleDialog(this.#args).name} to handle it before continuing.`);
response.push(`URL: ${summary.url}`);
response.push('### Category Scores');
for (const score of summary.scores) {
- response.push(
- `- ${score.title}: ${(score.score ?? 0) * 100} (${score.id})`,
- );
+ // Lighthouse uses a null score for categories that could not be
+ // scored and renders scores as Math.round(score * 100).
+ const formattedScore =
+ score.score === null ? 'n/a' : Math.round(score.score * 100);
+ response.push(`- ${score.title}: ${formattedScore} (${score.id})`);
}
response.push('### Audit Summary');
response.push(`Passed: ${summary.audits.passed}`);
diff --git a/tests/McpResponse.test.js.snapshot b/tests/McpResponse.test.js.snapshot
index 6af99afb..8cc182a5 100644
--- a/tests/McpResponse.test.js.snapshot
+++ b/tests/McpResponse.test.js.snapshot
@@ -1367,6 +1367,64 @@ exports[`lighthouse > includes lighthouse report paths 2`] = `
}
`;
+exports[`lighthouse > rounds category scores and shows unscored categories as n/a 1`] = `
+## Lighthouse Audit Results
+Mode: navigation
+Device: desktop
+URL: https://example.com
+### Category Scores
+- Accessibility: 57 (accessibility)
+- SEO: 0 (seo)
+- Agentic Browsing: n/a (agentic-browsing)
+### Audit Summary
+Passed: 10
+Failed: 1
+Total Timing: 1000ms
+### Reports
+- /tmp/report.json
+- /tmp/report.html
+`;
+
+exports[`lighthouse > rounds category scores and shows unscored categories as n/a 2`] = `
+{
+ "lighthouseResult": {
+ "summary": {
+ "mode": "navigation",
+ "device": "desktop",
+ "url": "https://example.com",
+ "scores": [
+ {
+ "id": "accessibility",
+ "title": "Accessibility",
+ "score": 0.57
+ },
+ {
+ "id": "seo",
+ "title": "SEO",
+ "score": 0
+ },
+ {
+ "id": "agentic-browsing",
+ "title": "Agentic Browsing",
+ "score": null
+ }
+ ],
+ "audits": {
+ "failed": 1,
+ "passed": 10
+ },
+ "timing": {
+ "total": 1000
+ }
+ },
+ "reports": [
+ "/tmp/report.json",
+ "/tmp/report.html"
+ ]
+ }
+}
+`;
+
exports[`third-party developer tools > lists third-party developer tools 1`] = `
## Third-party developer tools
My Tool Group: A group of tools
diff --git a/tests/McpResponse.test.ts b/tests/McpResponse.test.ts
index 34b26635..e10b141f 100644
--- a/tests/McpResponse.test.ts
+++ b/tests/McpResponse.test.ts
@@ -930,6 +930,54 @@ describe('lighthouse', () => {
t.assert.snapshot(stabilizeStructuredContent(structuredContent));
});
});
+
+ it('rounds category scores and shows unscored categories as n/a', async t => {
+ await withMcpContext(async (response, context) => {
+ const lighthouseResult = {
+ summary: {
+ mode: 'navigation',
+ device: 'desktop',
+ url: 'https://example.com',
+ scores: [
+ {
+ id: 'accessibility',
+ title: 'Accessibility',
+ score: 0.57,
+ },
+ {
+ id: 'seo',
+ title: 'SEO',
+ score: 0,
+ },
+ {
+ id: 'agentic-browsing',
+ title: 'Agentic Browsing',
+ score: null,
+ },
+ ],
+ audits: {
+ failed: 1,
+ passed: 10,
+ },
+ timing: {
+ total: 1000,
+ },
+ },
+ reports: ['/tmp/report.json', '/tmp/report.html'],
+ };
+
+ response.attachLighthouseResult(lighthouseResult);
+ const {content, structuredContent} = await response.handle(context);
+
+ const text = getTextContent(content[0]);
+ assert.ok(text.includes('- Accessibility: 57 (accessibility)'));
+ assert.ok(text.includes('- SEO: 0 (seo)'));
+ assert.ok(text.includes('- Agentic Browsing: n/a (agentic-browsing)'));
+
+ t.assert.snapshot(text);
+ t.assert.snapshot(stabilizeStructuredContent(structuredContent));
+ });
+ });
});
describe('third-party developer tools', () => {