chrome-devtools-mcp 0.25.0 → 1.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +55 -6
- package/build/src/DevtoolsUtils.js +13 -0
- package/build/src/HeapSnapshotManager.js +26 -2
- package/build/src/McpContext.js +3 -0
- package/build/src/McpResponse.js +51 -21
- package/build/src/ToolHandler.js +217 -0
- package/build/src/WaitForHelper.js +18 -4
- package/build/src/bin/check-latest-version.js +25 -1
- package/build/src/bin/chrome-devtools-cli-options.js +38 -2
- package/build/src/bin/chrome-devtools-mcp-cli-options.js +2 -8
- package/build/src/bin/chrome-devtools-mcp-main.js +4 -3
- package/build/src/bin/chrome-devtools.js +0 -2
- package/build/src/daemon/client.js +12 -6
- package/build/src/formatters/HeapSnapshotFormatter.js +27 -6
- package/build/src/index.js +11 -164
- package/build/src/telemetry/ClearcutLogger.js +34 -118
- package/build/src/telemetry/errors.js +18 -0
- package/build/src/telemetry/flagUtils.js +4 -3
- package/build/src/telemetry/{toolMetricsUtils.js → metricsRegistry.js} +3 -3
- package/build/src/telemetry/persistence.js +20 -2
- package/build/src/telemetry/transformation.js +134 -0
- package/build/src/telemetry/types.js +0 -8
- package/build/src/third_party/THIRD_PARTY_NOTICES +140 -857
- package/build/src/third_party/bundled-packages.json +3 -3
- package/build/src/third_party/devtools-formatter-worker.js +475 -146
- package/build/src/third_party/devtools-heap-snapshot-worker.js +39 -44
- package/build/src/third_party/index.js +4055 -30401
- package/build/src/third_party/issue-descriptions/genericBackUINavigationWouldSkipAd.md +4 -0
- package/build/src/third_party/lighthouse-devtools-mcp-bundle.js +4236 -4219
- package/build/src/tools/ToolDefinition.js +1 -1
- package/build/src/tools/emulation.js +3 -2
- package/build/src/tools/input.js +46 -16
- package/build/src/tools/lighthouse.js +7 -7
- package/build/src/tools/memory.js +24 -0
- package/build/src/tools/script.js +32 -10
- package/build/src/version.js +1 -1
- package/package.json +10 -7
- package/build/src/telemetry/metricUtils.js +0 -15
|
@@ -4,13 +4,14 @@
|
|
|
4
4
|
* SPDX-License-Identifier: Apache-2.0
|
|
5
5
|
*/
|
|
6
6
|
import { toSnakeCase } from '../utils/string.js';
|
|
7
|
+
import { stripUnderscoreBeforeNumber } from './transformation.js';
|
|
7
8
|
/**
|
|
8
9
|
* For enums, log the value as uppercase.
|
|
9
10
|
* We're going to have an enum for such flags with choices represented
|
|
10
11
|
* as an `enum` where the keys of the enum will map to the uppercase `choice`.
|
|
11
12
|
*/
|
|
12
13
|
function formatEnumChoice(snakeCaseName, choice) {
|
|
13
|
-
return `${snakeCaseName}_${choice}
|
|
14
|
+
return stripUnderscoreBeforeNumber(`${snakeCaseName}_${choice}`).toUpperCase();
|
|
14
15
|
}
|
|
15
16
|
/**
|
|
16
17
|
* Computes telemetry flag usage from parsed arguments and CLI options.
|
|
@@ -29,7 +30,7 @@ export function computeFlagUsage(args, options) {
|
|
|
29
30
|
const usage = {};
|
|
30
31
|
for (const [flagName, config] of Object.entries(options)) {
|
|
31
32
|
const value = args[flagName];
|
|
32
|
-
const snakeCaseName = toSnakeCase(flagName);
|
|
33
|
+
const snakeCaseName = stripUnderscoreBeforeNumber(toSnakeCase(flagName));
|
|
33
34
|
// If there isn't a default value provided for the flag,
|
|
34
35
|
// we're going to log whether it's present on the args user
|
|
35
36
|
// provided or not. If there is a default value, we only log presence
|
|
@@ -58,7 +59,7 @@ export function computeFlagUsage(args, options) {
|
|
|
58
59
|
export function getPossibleFlagMetrics(options) {
|
|
59
60
|
const metrics = [];
|
|
60
61
|
for (const [flagName, config] of Object.entries(options)) {
|
|
61
|
-
const snakeCaseName = toSnakeCase(flagName);
|
|
62
|
+
const snakeCaseName = stripUnderscoreBeforeNumber(toSnakeCase(flagName));
|
|
62
63
|
// _present is always a possible metric
|
|
63
64
|
metrics.push({
|
|
64
65
|
name: `${snakeCaseName}_present`,
|
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
* Copyright 2026 Google LLC
|
|
4
4
|
* SPDX-License-Identifier: Apache-2.0
|
|
5
5
|
*/
|
|
6
|
-
import { transformArgName, transformArgType, getZodType, PARAM_BLOCKLIST, } from './
|
|
6
|
+
import { transformArgName, transformArgType, getZodType, PARAM_BLOCKLIST, stripUnderscoreBeforeNumber, } from './transformation.js';
|
|
7
7
|
/**
|
|
8
8
|
* Validates that all values in an enum are of the homogeneous primitive type.
|
|
9
9
|
* Returns the primitive type string. Throws an error if heterogeneous.
|
|
@@ -81,9 +81,9 @@ export function generateToolMetrics(tools) {
|
|
|
81
81
|
});
|
|
82
82
|
}
|
|
83
83
|
return {
|
|
84
|
-
name: tool.name,
|
|
84
|
+
name: stripUnderscoreBeforeNumber(tool.name),
|
|
85
85
|
args,
|
|
86
86
|
};
|
|
87
87
|
});
|
|
88
88
|
}
|
|
89
|
-
//# sourceMappingURL=
|
|
89
|
+
//# sourceMappingURL=metricsRegistry.js.map
|
|
@@ -8,6 +8,8 @@ import os from 'node:os';
|
|
|
8
8
|
import path from 'node:path';
|
|
9
9
|
import process from 'node:process';
|
|
10
10
|
import { logger } from '../logger.js';
|
|
11
|
+
import { ClearcutLogger } from './ClearcutLogger.js';
|
|
12
|
+
import { ErrorCode } from './errors.js';
|
|
11
13
|
const STATE_FILE_NAME = 'telemetry_state.json';
|
|
12
14
|
function getDataFolder() {
|
|
13
15
|
const homedir = os.homedir();
|
|
@@ -28,12 +30,25 @@ export class FilePersistence {
|
|
|
28
30
|
this.#dataFolder = dataFolderOverride ?? getDataFolder();
|
|
29
31
|
}
|
|
30
32
|
async loadState() {
|
|
33
|
+
const filePath = path.join(this.#dataFolder, STATE_FILE_NAME);
|
|
34
|
+
try {
|
|
35
|
+
await fs.access(filePath);
|
|
36
|
+
}
|
|
37
|
+
catch {
|
|
38
|
+
// File doesn't exist. Not an error because new users do not have the state file.
|
|
39
|
+
return {
|
|
40
|
+
lastActive: '',
|
|
41
|
+
};
|
|
42
|
+
}
|
|
31
43
|
try {
|
|
32
|
-
const filePath = path.join(this.#dataFolder, STATE_FILE_NAME);
|
|
33
44
|
const content = await fs.readFile(filePath, 'utf-8');
|
|
34
45
|
return JSON.parse(content);
|
|
35
46
|
}
|
|
36
|
-
catch {
|
|
47
|
+
catch (error) {
|
|
48
|
+
logger(`Failed to read telemetry state from ${filePath}:`, error);
|
|
49
|
+
void ClearcutLogger.get()?.logServerError({
|
|
50
|
+
errorCode: ErrorCode.ERROR_CODE_PERSISTENCE_FILE_READ_FAILED,
|
|
51
|
+
});
|
|
37
52
|
return {
|
|
38
53
|
lastActive: '',
|
|
39
54
|
};
|
|
@@ -48,6 +63,9 @@ export class FilePersistence {
|
|
|
48
63
|
catch (error) {
|
|
49
64
|
// Ignore errors during state saving to avoid crashing the server
|
|
50
65
|
logger(`Failed to save telemetry state to ${filePath}:`, error);
|
|
66
|
+
void ClearcutLogger.get()?.logServerError({
|
|
67
|
+
errorCode: ErrorCode.ERROR_CODE_PERSISTENCE_FILE_SAVE_FAILED,
|
|
68
|
+
});
|
|
51
69
|
}
|
|
52
70
|
}
|
|
53
71
|
}
|
|
@@ -0,0 +1,134 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @license
|
|
3
|
+
* Copyright 2026 Google LLC
|
|
4
|
+
* SPDX-License-Identifier: Apache-2.0
|
|
5
|
+
*/
|
|
6
|
+
const LATENCY_BUCKETS = [50, 100, 250, 500, 1000, 2500, 5000, 10000];
|
|
7
|
+
export function bucketizeLatency(latencyMs) {
|
|
8
|
+
for (const bucket of LATENCY_BUCKETS) {
|
|
9
|
+
if (latencyMs <= bucket) {
|
|
10
|
+
return bucket;
|
|
11
|
+
}
|
|
12
|
+
}
|
|
13
|
+
return LATENCY_BUCKETS[LATENCY_BUCKETS.length - 1];
|
|
14
|
+
}
|
|
15
|
+
export const PARAM_BLOCKLIST = new Set(['uid', 'reqid', 'msgid']);
|
|
16
|
+
const SUPPORTED_ZOD_TYPES = [
|
|
17
|
+
'ZodString',
|
|
18
|
+
'ZodNumber',
|
|
19
|
+
'ZodBoolean',
|
|
20
|
+
'ZodArray',
|
|
21
|
+
'ZodEnum',
|
|
22
|
+
];
|
|
23
|
+
function isZodType(type) {
|
|
24
|
+
return SUPPORTED_ZOD_TYPES.includes(type);
|
|
25
|
+
}
|
|
26
|
+
export function getZodType(zodType) {
|
|
27
|
+
const def = zodType._def;
|
|
28
|
+
const typeName = def.typeName;
|
|
29
|
+
if (typeName === 'ZodOptional' ||
|
|
30
|
+
typeName === 'ZodDefault' ||
|
|
31
|
+
typeName === 'ZodNullable') {
|
|
32
|
+
return getZodType(def.innerType);
|
|
33
|
+
}
|
|
34
|
+
if (typeName === 'ZodEffects') {
|
|
35
|
+
return getZodType(def.schema);
|
|
36
|
+
}
|
|
37
|
+
if (isZodType(typeName)) {
|
|
38
|
+
return typeName;
|
|
39
|
+
}
|
|
40
|
+
throw new Error(`Unsupported zod type for tool parameter: ${typeName}`);
|
|
41
|
+
}
|
|
42
|
+
export function stripUnderscoreBeforeNumber(name) {
|
|
43
|
+
return name.replace(/_([0-9])/g, '$1');
|
|
44
|
+
}
|
|
45
|
+
export function transformArgName(zodType, name) {
|
|
46
|
+
const snakeCaseName = name.replace(/[A-Z]/g, letter => `_${letter.toLowerCase()}`);
|
|
47
|
+
let transformed;
|
|
48
|
+
if (zodType === 'ZodString') {
|
|
49
|
+
transformed = `${snakeCaseName}_length`;
|
|
50
|
+
}
|
|
51
|
+
else if (zodType === 'ZodArray') {
|
|
52
|
+
transformed = `${snakeCaseName}_count`;
|
|
53
|
+
}
|
|
54
|
+
else {
|
|
55
|
+
transformed = snakeCaseName;
|
|
56
|
+
}
|
|
57
|
+
return stripUnderscoreBeforeNumber(transformed);
|
|
58
|
+
}
|
|
59
|
+
export function transformArgType(zodType) {
|
|
60
|
+
if (zodType === 'ZodString' || zodType === 'ZodArray') {
|
|
61
|
+
return 'number';
|
|
62
|
+
}
|
|
63
|
+
switch (zodType) {
|
|
64
|
+
case 'ZodNumber':
|
|
65
|
+
return 'number';
|
|
66
|
+
case 'ZodBoolean':
|
|
67
|
+
return 'boolean';
|
|
68
|
+
case 'ZodEnum':
|
|
69
|
+
return 'enum';
|
|
70
|
+
default:
|
|
71
|
+
throw new Error(`Unsupported zod type for tool parameter: ${zodType}`);
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
const BUCKETS = [
|
|
75
|
+
0, 1, 2, 5, 10, 20, 50, 100, 200, 500, 1000, 2000, 5000, 10000,
|
|
76
|
+
];
|
|
77
|
+
function bucketize(value) {
|
|
78
|
+
for (const bucket of BUCKETS) {
|
|
79
|
+
if (bucket >= value) {
|
|
80
|
+
return bucket;
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
return BUCKETS[BUCKETS.length - 1];
|
|
84
|
+
}
|
|
85
|
+
function transformValue(zodType, value) {
|
|
86
|
+
if (zodType === 'ZodString') {
|
|
87
|
+
return bucketize(value.length);
|
|
88
|
+
}
|
|
89
|
+
else if (zodType === 'ZodArray') {
|
|
90
|
+
return value.length;
|
|
91
|
+
}
|
|
92
|
+
else {
|
|
93
|
+
return value;
|
|
94
|
+
}
|
|
95
|
+
}
|
|
96
|
+
function hasEquivalentType(zodType, value) {
|
|
97
|
+
if (zodType === 'ZodString') {
|
|
98
|
+
return typeof value === 'string';
|
|
99
|
+
}
|
|
100
|
+
else if (zodType === 'ZodArray') {
|
|
101
|
+
return Array.isArray(value);
|
|
102
|
+
}
|
|
103
|
+
else if (zodType === 'ZodNumber') {
|
|
104
|
+
return typeof value === 'number';
|
|
105
|
+
}
|
|
106
|
+
else if (zodType === 'ZodBoolean') {
|
|
107
|
+
return typeof value === 'boolean';
|
|
108
|
+
}
|
|
109
|
+
else if (zodType === 'ZodEnum') {
|
|
110
|
+
return (typeof value === 'string' ||
|
|
111
|
+
typeof value === 'number' ||
|
|
112
|
+
typeof value === 'boolean');
|
|
113
|
+
}
|
|
114
|
+
else {
|
|
115
|
+
return false;
|
|
116
|
+
}
|
|
117
|
+
}
|
|
118
|
+
export function sanitizeParams(params, schema) {
|
|
119
|
+
const transformed = {};
|
|
120
|
+
for (const [name, value] of Object.entries(params)) {
|
|
121
|
+
if (PARAM_BLOCKLIST.has(name)) {
|
|
122
|
+
continue;
|
|
123
|
+
}
|
|
124
|
+
const zodType = getZodType(schema[name]);
|
|
125
|
+
if (!hasEquivalentType(zodType, value)) {
|
|
126
|
+
throw new Error(`parameter ${name} has type ${zodType} but value ${value} is not of equivalent type`);
|
|
127
|
+
}
|
|
128
|
+
const transformedName = transformArgName(zodType, name);
|
|
129
|
+
const transformedValue = transformValue(zodType, value);
|
|
130
|
+
transformed[transformedName] = transformedValue;
|
|
131
|
+
}
|
|
132
|
+
return transformed;
|
|
133
|
+
}
|
|
134
|
+
//# sourceMappingURL=transformation.js.map
|
|
@@ -11,14 +11,6 @@ export var OsType;
|
|
|
11
11
|
OsType[OsType["OS_TYPE_MACOS"] = 2] = "OS_TYPE_MACOS";
|
|
12
12
|
OsType[OsType["OS_TYPE_LINUX"] = 3] = "OS_TYPE_LINUX";
|
|
13
13
|
})(OsType || (OsType = {}));
|
|
14
|
-
export var ChromeChannel;
|
|
15
|
-
(function (ChromeChannel) {
|
|
16
|
-
ChromeChannel[ChromeChannel["CHROME_CHANNEL_UNSPECIFIED"] = 0] = "CHROME_CHANNEL_UNSPECIFIED";
|
|
17
|
-
ChromeChannel[ChromeChannel["CHROME_CHANNEL_CANARY"] = 1] = "CHROME_CHANNEL_CANARY";
|
|
18
|
-
ChromeChannel[ChromeChannel["CHROME_CHANNEL_DEV"] = 2] = "CHROME_CHANNEL_DEV";
|
|
19
|
-
ChromeChannel[ChromeChannel["CHROME_CHANNEL_BETA"] = 3] = "CHROME_CHANNEL_BETA";
|
|
20
|
-
ChromeChannel[ChromeChannel["CHROME_CHANNEL_STABLE"] = 4] = "CHROME_CHANNEL_STABLE";
|
|
21
|
-
})(ChromeChannel || (ChromeChannel = {}));
|
|
22
14
|
export var McpClient;
|
|
23
15
|
(function (McpClient) {
|
|
24
16
|
McpClient[McpClient["MCP_CLIENT_UNSPECIFIED"] = 0] = "MCP_CLIENT_UNSPECIFIED";
|