Skip to content

Chrome DevTools for coding agents

refactor: move files to folders that better represent their use (#2564)

Nikolay Vitkov06b7a5c3209a
diff --git a/src/McpContext.ts b/src/McpContext.ts
index 13fd8b2d..52031c03 100644
--- a/src/McpContext.ts
+++ b/src/McpContext.ts
@@ -10,17 +10,17 @@ import path from 'node:path';
import {fileURLToPath, pathToFileURL} from 'node:url';
import {overrideDevToolsGlobals} from './devtools/DevtoolsUtils.js';
-import {HeapSnapshotManager} from './HeapSnapshotManager.js';
+import {HeapSnapshotManager} from './processors/HeapSnapshotManager.js';
import type {
HeapSnapshotAggregateData,
HeapSnapshotClassDiff,
HeapSnapshotDetailedClassDiff,
DuplicateStringGroup,
HeapEdgesQueryOptions,
-} from './HeapSnapshotManager.js';
+} from './processors/HeapSnapshotManager.js';
import {McpPage} from './McpPage.js';
-import {type UncaughtError} from './PageCollector.js';
-import {ServiceWorkerConsoleCollector} from './ServiceWorkerCollector.js';
+import {type UncaughtError} from './collectors/PageCollector.js';
+import {ServiceWorkerConsoleCollector} from './collectors/ServiceWorkerCollector.js';
import {
Locator,
type Browser,
@@ -45,7 +45,7 @@ import type {
DevToolsData,
SupportedExtensions,
} from './tools/ToolDefinition.js';
-import type {TraceResult} from './trace-processing/parse.js';
+import type {TraceResult} from './processors/PerformanceTrace.js';
import type {Logger} from './types.js';
import type {ExtensionServiceWorker} from './types.js';
import {getTempFilePath, resolveCanonicalPath} from './utils/files.js';
diff --git a/src/McpPage.ts b/src/McpPage.ts
index f3e2aff6..ecfcfe18 100644
--- a/src/McpPage.ts
+++ b/src/McpPage.ts
@@ -64,7 +64,7 @@ import {
NetworkCollector,
type ListenerMap,
type UncaughtError,
-} from './PageCollector.js';
+} from './collectors/PageCollector.js';
import {TextSnapshot} from './TextSnapshot.js';
import type {Locator} from './third_party/index.js';
import {
@@ -100,7 +100,7 @@ import {
WaitForHelper,
type WaitForEventsResult,
type DialogAction,
-} from './WaitForHelper.js';
+} from './utils/WaitForHelper.js';
/**
* Per-page state wrapper. Consolidates dialog, snapshot, emulation,
diff --git a/src/McpResponse.ts b/src/McpResponse.ts
index c1cea408..af9fbbc7 100644
--- a/src/McpResponse.ts
+++ b/src/McpResponse.ts
@@ -21,10 +21,10 @@ import type {
HeapSnapshotClassDiff,
HeapSnapshotDetailedClassDiff,
DuplicateStringGroup,
-} from './HeapSnapshotManager.js';
+} from './processors/HeapSnapshotManager.js';
import type {McpContext} from './McpContext.js';
import type {McpPage} from './McpPage.js';
-import {UncaughtError} from './PageCollector.js';
+import {UncaughtError} from './collectors/PageCollector.js';
import {TextSnapshot} from './TextSnapshot.js';
import {DevTools, getToonEncode, getGcfEncode} from './third_party/index.js';
import type {
@@ -45,13 +45,17 @@ import type {
Response,
SnapshotParams,
} from './tools/ToolDefinition.js';
-import type {InsightName, TraceResult} from './trace-processing/parse.js';
-import {getInsightOutput, getTraceSummary} from './trace-processing/parse.js';
+import {
+ type InsightName,
+ type TraceResult,
+ getInsightOutput,
+ getTraceSummary,
+} from './processors/PerformanceTrace.js';
import type {PaginationOptions} from './types.js';
import type {WithSymbolId} from './utils/id.js';
import {stableIdSymbol} from './utils/id.js';
import {paginate} from './utils/pagination.js';
-import type {WaitForEventsResult} from './WaitForHelper.js';
+import type {WaitForEventsResult} from './utils/WaitForHelper.js';
const {formatBytesToKb} = DevTools.I18n.ByteUtilities;
@@ -755,7 +759,10 @@ export class McpResponse implements Response {
consoleMessage?: object;
consoleMessages?: object[];
traceSummary?: string;
- traceInsights?: Array<{insightName: string; insightKey: string}>;
+ traceInsights?: Array<{
+ insightName: string;
+ insightKey: string | undefined;
+ }>;
lighthouseResult?: object;
extensions?: object[];
thirdPartyDeveloperTools?: object[];
@@ -1013,7 +1020,12 @@ Call ${handleDialog.name} to handle it before continuing.`);
for (const [insightName, model] of Object.entries(insightSet.model)) {
structuredContent.traceInsights.push({
insightName,
- insightKey: model.insightKey,
+ insightKey:
+ typeof model === 'object' &&
+ model !== null &&
+ 'insightKey' in model
+ ? model.insightKey
+ : undefined,
});
}
}
diff --git a/src/PageCollector.ts b/src/collectors/PageCollector.ts
similarity index 97%
rename from src/PageCollector.ts
rename to src/collectors/PageCollector.ts
index 28f8c4a1..a8ae2682 100644
--- a/src/PageCollector.ts
+++ b/src/collectors/PageCollector.ts
@@ -4,27 +4,27 @@
* SPDX-License-Identifier: Apache-2.0
*/
-import {FakeIssuesManager} from './devtools/DevtoolsUtils.js';
+import {FakeIssuesManager} from '../devtools/DevtoolsUtils.js';
import type {
CDPSession,
ConsoleMessage,
Protocol,
Issue,
-} from './third_party/index.js';
-import {DevTools} from './third_party/index.js';
+} from '../third_party/index.js';
+import {DevTools} from '../third_party/index.js';
import {
type Frame,
type Handler,
type HTTPRequest,
type Page,
type PageEvents as PuppeteerPageEvents,
-} from './third_party/index.js';
+} from '../third_party/index.js';
import {
createIdGenerator,
stableIdSymbol,
type WithSymbolId,
-} from './utils/id.js';
-import {logger} from './utils/logger.js';
+} from '../utils/id.js';
+import {logger} from '../utils/logger.js';
export class UncaughtError {
readonly details: Protocol.Runtime.ExceptionDetails;
diff --git a/src/ServiceWorkerCollector.ts b/src/collectors/ServiceWorkerCollector.ts
similarity index 96%
rename from src/ServiceWorkerCollector.ts
rename to src/collectors/ServiceWorkerCollector.ts
index 562ffeb3..b1a847f2 100644
--- a/src/ServiceWorkerCollector.ts
+++ b/src/collectors/ServiceWorkerCollector.ts
@@ -12,10 +12,10 @@ import type {
CDPSession,
Protocol,
Browser,
-} from './third_party/index.js';
-import type {ExtensionServiceWorker} from './types.js';
-import type {WithSymbolId} from './utils/id.js';
-import {createIdGenerator, stableIdSymbol} from './utils/id.js';
+} from '../third_party/index.js';
+import type {ExtensionServiceWorker} from '../types.js';
+import type {WithSymbolId} from '../utils/id.js';
+import {createIdGenerator, stableIdSymbol} from '../utils/id.js';
const CHROME_EXTENSION_PREFIX = 'chrome-extension://';
diff --git a/src/formatters/ConsoleFormatter.ts b/src/formatters/ConsoleFormatter.ts
index 50dcc5de..aada6a3b 100644
--- a/src/formatters/ConsoleFormatter.ts
+++ b/src/formatters/ConsoleFormatter.ts
@@ -9,7 +9,7 @@ import {
type TargetUniverse,
SymbolizedError,
} from '../devtools/DevtoolsUtils.js';
-import {UncaughtError} from '../PageCollector.js';
+import {UncaughtError} from '../collectors/PageCollector.js';
import * as DevTools from '../third_party/index.js';
import type {ConsoleMessage} from '../third_party/index.js';
diff --git a/src/formatters/HeapSnapshotFormatter.ts b/src/formatters/HeapSnapshotFormatter.ts
index 7ec08dc4..f32e0a3f 100644
--- a/src/formatters/HeapSnapshotFormatter.ts
+++ b/src/formatters/HeapSnapshotFormatter.ts
@@ -9,7 +9,7 @@ import type {
HeapSnapshotClassDiff,
HeapSnapshotDetailedClassDiff,
DuplicateStringGroup,
-} from '../HeapSnapshotManager.js';
+} from '../processors/HeapSnapshotManager.js';
import {DevTools} from '../third_party/index.js';
import {stableIdSymbol} from '../utils/id.js';
diff --git a/src/HeapSnapshotManager.ts b/src/processors/HeapSnapshotManager.ts
similarity index 98%
rename from src/HeapSnapshotManager.ts
rename to src/processors/HeapSnapshotManager.ts
index cdf5ac48..7b848f2c 100644
--- a/src/HeapSnapshotManager.ts
+++ b/src/processors/HeapSnapshotManager.ts
@@ -7,12 +7,12 @@
import fsSync from 'node:fs';
import path from 'node:path';
-import {DevTools} from './third_party/index.js';
+import {DevTools} from '../third_party/index.js';
import {
createIdGenerator,
stableIdSymbol,
type WithSymbolId,
-} from './utils/id.js';
+} from '../utils/id.js';
export type AggregatedInfoWithId =
WithSymbolId<DevTools.HeapSnapshotModel.HeapSnapshotModel.AggregatedInfo>;
@@ -366,7 +366,7 @@ export class HeapSnapshotManager {
/* noop */
},
DevTools.Common.Console.Console.instance(),
- import.meta.resolve('./third_party/devtools-heap-snapshot-worker.js'),
+ import.meta.resolve('../third_party/devtools-heap-snapshot-worker.js'),
);
try {
diff --git a/src/trace-processing/parse.ts b/src/processors/PerformanceTrace.ts
similarity index 100%
rename from src/trace-processing/parse.ts
rename to src/processors/PerformanceTrace.ts
diff --git a/src/tools/ToolDefinition.ts b/src/tools/ToolDefinition.ts
index 64b0861a..8d557259 100644
--- a/src/tools/ToolDefinition.ts
+++ b/src/tools/ToolDefinition.ts
@@ -11,7 +11,7 @@ import type {
HeapSnapshotDetailedClassDiff,
DuplicateStringGroup,
HeapEdgesQueryOptions,
-} from '../HeapSnapshotManager.js';
+} from '../processors/HeapSnapshotManager.js';
import type {McpPage} from '../McpPage.js';
import {zod} from '../third_party/index.js';
import type {
@@ -29,14 +29,17 @@ import type {
Protocol,
Page,
} from '../third_party/index.js';
-import type {InsightName, TraceResult} from '../trace-processing/parse.js';
+import type {InsightName, TraceResult} from '../processors/PerformanceTrace.js';
import type {
TextSnapshotNode,
GeolocationOptions,
ExtensionServiceWorker,
} from '../types.js';
import type {PaginationOptions} from '../types.js';
-import type {WaitForEventsResult, DialogAction} from '../WaitForHelper.js';
+import type {
+ WaitForEventsResult,
+ DialogAction,
+} from '../utils/WaitForHelper.js';
import type {ToolCategory} from './categories.js';
import type {ToolGroups} from './thirdPartyDeveloper.js';
diff --git a/src/tools/input.ts b/src/tools/input.ts
index f5b74cd2..8c301296 100644
--- a/src/tools/input.ts
+++ b/src/tools/input.ts
@@ -10,7 +10,7 @@ import type {ElementHandle, KeyInput} from '../third_party/index.js';
import type {TextSnapshotNode} from '../types.js';
import {parseKey} from '../utils/keyboard.js';
import {logger} from '../utils/logger.js';
-import type {WaitForEventsResult} from '../WaitForHelper.js';
+import type {WaitForEventsResult} from '../utils/WaitForHelper.js';
import {ToolCategory} from './categories.js';
import type {ContextPage} from './ToolDefinition.js';
diff --git a/src/tools/performance.ts b/src/tools/performance.ts
index 2eb6bdfa..cb779f4b 100644
--- a/src/tools/performance.ts
+++ b/src/tools/performance.ts
@@ -7,11 +7,11 @@
import zlib from 'node:zlib';
import {zod, DevTools} from '../third_party/index.js';
-import type {InsightName, TraceResult} from '../trace-processing/parse.js';
+import type {InsightName, TraceResult} from '../processors/PerformanceTrace.js';
import {
parseRawTraceBuffer,
traceResultIsSuccess,
-} from '../trace-processing/parse.js';
+} from '../processors/PerformanceTrace.js';
import {logger} from '../utils/logger.js';
import {ToolCategory} from './categories.js';
diff --git a/src/WaitForHelper.ts b/src/utils/WaitForHelper.ts
similarity index 97%
rename from src/WaitForHelper.ts
rename to src/utils/WaitForHelper.ts
index e31f91e0..0289bfa5 100644
--- a/src/WaitForHelper.ts
+++ b/src/utils/WaitForHelper.ts
@@ -4,9 +4,9 @@
* SPDX-License-Identifier: Apache-2.0
*/
-import type {Page, Protocol, CdpPage, Dialog} from './third_party/index.js';
-import type {PredefinedNetworkConditions} from './third_party/index.js';
-import {logger} from './utils/logger.js';
+import type {Page, Protocol, CdpPage, Dialog} from '../third_party/index.js';
+import type {PredefinedNetworkConditions} from '../third_party/index.js';
+import {logger} from './logger.js';
export type DialogAction = 'accept' | 'dismiss' | string;
diff --git a/tests/McpContext.test.ts b/tests/McpContext.test.ts
index 2af2277e..81fd7b05 100644
--- a/tests/McpContext.test.ts
+++ b/tests/McpContext.test.ts
@@ -20,7 +20,7 @@ import {McpContext} from '../src/McpContext.js';
import {McpPage} from '../src/McpPage.js';
import {TextSnapshot} from '../src/TextSnapshot.js';
import {type HTTPResponse} from '../src/third_party/index.js';
-import type {TraceResult} from '../src/trace-processing/parse.js';
+import type {TraceResult} from '../src/processors/PerformanceTrace.js';
import {
getMockRequest,
diff --git a/tests/McpResponse.test.ts b/tests/McpResponse.test.ts
index 3f80bc68..119af73c 100644
--- a/tests/McpResponse.test.ts
+++ b/tests/McpResponse.test.ts
@@ -23,11 +23,11 @@ import {
newPage,
selectPage,
} from '../src/tools/pages.js';
-import type {InsightName} from '../src/trace-processing/parse.js';
+import type {InsightName} from '../src/processors/PerformanceTrace.js';
import {
parseRawTraceBuffer,
traceResultIsSuccess,
-} from '../src/trace-processing/parse.js';
+} from '../src/processors/PerformanceTrace.js';
import {serverHooks} from './server.js';
import {loadTraceAsBuffer} from './trace-processing/fixtures/load.js';
diff --git a/tests/PageCollector.test.ts b/tests/collectors/PageCollector.test.ts
similarity index 98%
rename from tests/PageCollector.test.ts
rename to tests/collectors/PageCollector.test.ts
index 6beed030..fa7c2657 100644
--- a/tests/PageCollector.test.ts
+++ b/tests/collectors/PageCollector.test.ts
@@ -10,15 +10,15 @@ import {afterEach, beforeEach, describe, it} from 'node:test';
import type {Frame, HTTPRequest, Protocol} from 'puppeteer-core';
import sinon from 'sinon';
-import type {ListenerMap} from '../src/PageCollector.js';
+import type {ListenerMap} from '../../src/collectors/PageCollector.js';
import {
ConsoleCollector,
NetworkCollector,
PageCollector,
-} from '../src/PageCollector.js';
-import {DevTools} from '../src/third_party/index.js';
+} from '../../src/collectors/PageCollector.js';
+import {DevTools} from '../../src/third_party/index.js';
-import {getMockRequest, getMockBrowser} from './utils.js';
+import {getMockRequest, getMockBrowser} from '../utils.js';
describe('PageCollector', () => {
it('works', async () => {
diff --git a/tests/ServiceWorkerCollector.test.ts b/tests/collectors/ServiceWorkerCollector.test.ts
similarity index 86%
rename from tests/ServiceWorkerCollector.test.ts
rename to tests/collectors/ServiceWorkerCollector.test.ts
index 2417e7a6..194f94f4 100644
--- a/tests/ServiceWorkerCollector.test.ts
+++ b/tests/collectors/ServiceWorkerCollector.test.ts
@@ -7,10 +7,10 @@
import assert from 'node:assert';
import {describe, it} from 'node:test';
-import {UncaughtError} from '../src/PageCollector.js';
-import {ServiceWorkerConsoleCollector} from '../src/ServiceWorkerCollector.js';
-import type {Protocol} from '../src/third_party/index.js';
-import {stableIdSymbol} from '../src/utils/id.js';
+import {UncaughtError} from '../../src/collectors/PageCollector.js';
+import {ServiceWorkerConsoleCollector} from '../../src/collectors/ServiceWorkerCollector.js';
+import type {Protocol} from '../../src/third_party/index.js';
+import {stableIdSymbol} from '../../src/utils/id.js';
describe('ServiceWorkerConsoleCollector', () => {
it('limits logs to 1000 per extension', () => {
diff --git a/tests/formatters/ConsoleFormatter.test.ts b/tests/formatters/ConsoleFormatter.test.ts
index cae3aeff..e037cc02 100644
--- a/tests/formatters/ConsoleFormatter.test.ts
+++ b/tests/formatters/ConsoleFormatter.test.ts
@@ -8,7 +8,7 @@ import {describe, it} from 'node:test';
import {SymbolizedError} from '../../src/devtools/DevtoolsUtils.js';
import {ConsoleFormatter} from '../../src/formatters/ConsoleFormatter.js';
-import {UncaughtError} from '../../src/PageCollector.js';
+import {UncaughtError} from '../../src/collectors/PageCollector.js';
import type {ConsoleMessage, Protocol} from '../../src/third_party/index.js';
import type {DevTools} from '../../src/third_party/index.js';
diff --git a/tests/HeapSnapshotManager.test.ts b/tests/processors/HeapSnapshotManager.test.ts
similarity index 88%
rename from tests/HeapSnapshotManager.test.ts
rename to tests/processors/HeapSnapshotManager.test.ts
index ee5cb259..65a2ffee 100644
--- a/tests/HeapSnapshotManager.test.ts
+++ b/tests/processors/HeapSnapshotManager.test.ts
@@ -9,8 +9,8 @@ import {describe, it, afterEach} from 'node:test';
import sinon from 'sinon';
-import {HeapSnapshotManager} from '../src/HeapSnapshotManager.js';
-import {DevTools} from '../src/third_party/index.js';
+import {HeapSnapshotManager} from '../../src/processors/HeapSnapshotManager.js';
+import {DevTools} from '../../src/third_party/index.js';
describe('HeapSnapshotManager', () => {
afterEach(() => {
diff --git a/tests/tools/performance.test.ts b/tests/tools/performance.test.ts
index aaadf13a..3e702af0 100644
--- a/tests/tools/performance.test.ts
+++ b/tests/tools/performance.test.ts
@@ -15,11 +15,11 @@ import {
startTrace,
stopTrace,
} from '../../src/tools/performance.js';
-import type {TraceResult} from '../../src/trace-processing/parse.js';
import {
parseRawTraceBuffer,
+ type TraceResult,
traceResultIsSuccess,
-} from '../../src/trace-processing/parse.js';
+} from '../../src/processors/PerformanceTrace.js';
import {loadTraceAsBuffer} from '../trace-processing/fixtures/load.js';
import {withMcpContext} from '../utils.js';
diff --git a/tests/tools/script.test.ts b/tests/tools/script.test.ts
index c590cca7..f5689293 100644
--- a/tests/tools/script.test.ts
+++ b/tests/tools/script.test.ts
@@ -14,7 +14,7 @@ import type {ParsedArguments} from '../../src/bin/chrome-devtools-mcp-cli-option
import {TextSnapshot} from '../../src/TextSnapshot.js';
import {installExtension} from '../../src/tools/extensions.js';
import {evaluateScript} from '../../src/tools/script.js';
-import {WaitForHelper} from '../../src/WaitForHelper.js';
+import {WaitForHelper} from '../../src/utils/WaitForHelper.js';
import {serverHooks} from '../server.js';
import {
assertNoServiceWorkerReported,
diff --git a/tests/trace-processing/parse.test.ts b/tests/trace-processing/parse.test.ts
index 19510ffc..375160ff 100644
--- a/tests/trace-processing/parse.test.ts
+++ b/tests/trace-processing/parse.test.ts
@@ -10,7 +10,7 @@ import {describe, it} from 'node:test';
import {
getTraceSummary,
parseRawTraceBuffer,
-} from '../../src/trace-processing/parse.js';
+} from '../../src/processors/PerformanceTrace.js';
import {loadTraceAsBuffer} from './fixtures/load.js';
diff --git a/tests/WaitForHelper.test.ts b/tests/utils/WaitForHelper.test.ts
similarity index 98%
rename from tests/WaitForHelper.test.ts
rename to tests/utils/WaitForHelper.test.ts
index 86087687..27ea5f9d 100644
--- a/tests/WaitForHelper.test.ts
+++ b/tests/utils/WaitForHelper.test.ts
@@ -7,8 +7,8 @@
import assert from 'node:assert';
import {describe, it} from 'node:test';
-import {serverHooks} from './server.js';
-import {html, withMcpContext} from './utils.js';
+import {serverHooks} from '../server.js';
+import {html, withMcpContext} from '../utils.js';
describe('WaitForHelper', () => {
const server = serverHooks();
diff --git a/tests/check-for-updates.test.ts b/tests/utils/check-for-updates.test.ts
similarity index 98%
rename from tests/check-for-updates.test.ts
rename to tests/utils/check-for-updates.test.ts
index 2dec14fe..eba35d2e 100644
--- a/tests/check-for-updates.test.ts
+++ b/tests/utils/check-for-updates.test.ts
@@ -16,8 +16,8 @@ import sinon from 'sinon';
import {
checkForUpdates,
resetUpdateCheckFlagForTesting,
-} from '../src/utils/check-for-updates.js';
-import {VERSION} from '../src/version.js';
+} from '../../src/utils/check-for-updates.js';
+import {VERSION} from '../../src/version.js';
describe('checkForUpdates', () => {
beforeEach(() => {