Skip to content

Chrome DevTools for coding agents

chore(eslint): add require-parsed-arguments rule (#2770)

Nikolay Vitkov7fee48bcfd9c
diff --git a/eslint.config.js b/eslint.config.js
index 4c2f8f42..64eb25c7 100644
--- a/eslint.config.js
+++ b/eslint.config.js
@@ -154,6 +154,7 @@ export default defineConfig([
files: ['src/tools/**/*.ts'],
rules: {
'@local/enforce-zod-schema': 'error',
+ '@local/require-parsed-arguments': 'error',
},
},
{
diff --git a/scripts/eslint_rules/local-plugin.js b/scripts/eslint_rules/local-plugin.js
index a37fb295..481caf48 100644
--- a/scripts/eslint_rules/local-plugin.js
+++ b/scripts/eslint_rules/local-plugin.js
@@ -6,6 +6,7 @@
import checkLicenseRule from './check-license-rule.js';
import enforceZodSchemaRule from './enforce-zod-schema-rule.js';
+import requireParsedArgumentsRule from './require-parsed-arguments-rule.js';
import noDirectThirdPartyImportsRule from './no-direct-third-party-imports-rule.js';
export default {
@@ -13,5 +14,6 @@ export default {
'check-license': checkLicenseRule,
'no-direct-third-party-imports': noDirectThirdPartyImportsRule,
'enforce-zod-schema': enforceZodSchemaRule,
+ 'require-parsed-arguments': requireParsedArgumentsRule,
},
};
diff --git a/scripts/eslint_rules/require-parsed-arguments-rule.js b/scripts/eslint_rules/require-parsed-arguments-rule.js
new file mode 100644
index 00000000..fd82dd8f
--- /dev/null
+++ b/scripts/eslint_rules/require-parsed-arguments-rule.js
@@ -0,0 +1,118 @@
+/**
+ * @license
+ * Copyright 2026 Google LLC
+ * SPDX-License-Identifier: Apache-2.0
+ */
+
+export default {
+ meta: {
+ type: 'problem',
+ fixable: 'code',
+ docs: {
+ description:
+ 'Ensure defineTool and definePageTool callbacks are type-annotated with ParsedArguments',
+ },
+ schema: [],
+ messages: {
+ missingAnnotation:
+ 'The callback to {{name}} must specify its argument type as ParsedArguments.',
+ },
+ },
+ create(context) {
+ return {
+ CallExpression(node) {
+ if (
+ node.callee.type === 'Identifier' &&
+ (node.callee.name === 'defineTool' ||
+ node.callee.name === 'definePageTool')
+ ) {
+ const arg = node.arguments[0];
+ if (
+ arg &&
+ (arg.type === 'ArrowFunctionExpression' ||
+ arg.type === 'FunctionExpression')
+ ) {
+ if (arg.params.length > 0) {
+ const firstParam = arg.params[0];
+ if (
+ firstParam.typeAnnotation &&
+ firstParam.typeAnnotation.type === 'TSTypeAnnotation'
+ ) {
+ const typeRef = firstParam.typeAnnotation.typeAnnotation;
+ if (
+ typeRef.type === 'TSTypeReference' &&
+ typeRef.typeName.name === 'ParsedArguments'
+ ) {
+ return;
+ }
+ }
+
+ context.report({
+ node: arg,
+ messageId: 'missingAnnotation',
+ data: {
+ name: node.callee.name,
+ },
+ fix(fixer) {
+ const sourceCode =
+ context.sourceCode || context.getSourceCode();
+
+ // The arrow function might start with `async`, so find the param token
+ const paramToken = sourceCode.getFirstToken(firstParam);
+ const beforeParamToken =
+ sourceCode.getTokenBefore(paramToken);
+
+ // If the token before the param is open paren, and that open paren is part of the arrow function
+ // Then it has parens around parameters.
+ // Wait, actually, the most reliable way is if the ArrowFunctionExpression's first token is `(`
+ // OR if it's `async (`, in which case the token before `param` is `(`.
+ // BUT it must be inside the ArrowFunctionExpression.
+ // Since it's a parameter of the function `arg`, we can check if `beforeParamToken` is within `arg.range`.
+ let hasParens = false;
+ if (
+ beforeParamToken &&
+ beforeParamToken.value === '(' &&
+ beforeParamToken.range[0] >= arg.range[0]
+ ) {
+ hasParens = true;
+ }
+
+ let paramName = firstParam.name;
+ if (!paramName) {
+ if (firstParam.type === 'Identifier') {
+ paramName = firstParam.name;
+ } else if (firstParam.type === 'AssignmentPattern') {
+ const left = sourceCode.getText(firstParam.left);
+ const right = sourceCode.getText(firstParam.right);
+ const output = `${left}: ParsedArguments = ${right}`;
+ if (hasParens) {
+ return fixer.replaceText(firstParam, output);
+ } else {
+ return fixer.replaceText(firstParam, `(${output})`);
+ }
+ } else {
+ const text = sourceCode.getText(firstParam);
+ paramName = text.split(':')[0].trim();
+ }
+ }
+
+ if (hasParens) {
+ return fixer.replaceText(
+ firstParam,
+ `${paramName}: ParsedArguments`,
+ );
+ } else {
+ return fixer.replaceText(
+ firstParam,
+ `(${paramName}: ParsedArguments)`,
+ );
+ }
+ },
+ });
+ }
+ }
+ }
+ },
+ };
+ },
+};
diff --git a/src/tools/console.ts b/src/tools/console.ts
index 47272924..decafd02 100644
--- a/src/tools/console.ts
+++ b/src/tools/console.ts
@@ -4,6 +4,7 @@
* SPDX-License-Identifier: Apache-2.0
*/
+import type {ParsedArguments} from '../config/mcp-options.js';
import {zod} from '../third_party/index.js';
import type {ConsoleMessageType} from '../third_party/index.js';
@@ -39,72 +40,74 @@ const FILTERABLE_MESSAGE_TYPES: [
const LIST_CONSOLE_MESSAGES_TOOL_NAME = 'list_console_messages';
-export const listConsoleMessages = definePageTool(cliArgs => {
- return {
- name: LIST_CONSOLE_MESSAGES_TOOL_NAME,
- description: `List all console messages for the target page since the last navigation.${cliArgs?.categoryExtensions ? ' This includes console messages originating from extensions content scripts.' : ''}`,
- annotations: {
- category: ToolCategory.DEBUGGING,
- readOnlyHint: true,
- },
- schema: {
- pageSize: zod
- .number()
- .int()
- .positive()
- .optional()
- .describe(
- 'Maximum number of messages to return. When omitted, returns all messages.',
- ),
- pageIdx: zod
- .number()
- .int()
- .min(0)
- .optional()
- .describe(
- 'Page number to return (0-based). When omitted, returns the first page.',
- ),
- types: zod
- .array(zod.enum(FILTERABLE_MESSAGE_TYPES))
- .optional()
- .describe(
- 'Filter messages to only return messages of the specified resource types. When omitted or empty, returns all messages.',
- ),
- includePreservedMessages: zod
- .boolean()
- .default(false)
- .optional()
- .describe(
- 'Set to true to return the preserved messages over the last 3 navigations.',
- ),
- includeStackTraces: zod
- .boolean()
- .default(false)
- .optional()
- .describe(
- 'Set to true to include the stack trace for each message when available. Increases the response size.',
- ),
- serviceWorkerId: zod
- .string()
- .optional()
- .describe(
- 'Filter messages to only return messages of the specified service worker.',
- ),
- },
- blockedByDialog: false,
- verifyFilesSchema: {},
- handler: async (request, response) => {
- response.setIncludeConsoleData(true, {
- pageSize: request.params.pageSize,
- pageIdx: request.params.pageIdx,
- types: request.params.types,
- includePreservedMessages: request.params.includePreservedMessages,
- includeStackTraces: request.params.includeStackTraces,
- serviceWorkerId: request.params.serviceWorkerId,
- });
- },
- };
-});
+export const listConsoleMessages = definePageTool(
+ (cliArgs: ParsedArguments) => {
+ return {
+ name: LIST_CONSOLE_MESSAGES_TOOL_NAME,
+ description: `List all console messages for the target page since the last navigation.${cliArgs?.categoryExtensions ? ' This includes console messages originating from extensions content scripts.' : ''}`,
+ annotations: {
+ category: ToolCategory.DEBUGGING,
+ readOnlyHint: true,
+ },
+ schema: {
+ pageSize: zod
+ .number()
+ .int()
+ .positive()
+ .optional()
+ .describe(
+ 'Maximum number of messages to return. When omitted, returns all messages.',
+ ),
+ pageIdx: zod
+ .number()
+ .int()
+ .min(0)
+ .optional()
+ .describe(
+ 'Page number to return (0-based). When omitted, returns the first page.',
+ ),
+ types: zod
+ .array(zod.enum(FILTERABLE_MESSAGE_TYPES))
+ .optional()
+ .describe(
+ 'Filter messages to only return messages of the specified resource types. When omitted or empty, returns all messages.',
+ ),
+ includePreservedMessages: zod
+ .boolean()
+ .default(false)
+ .optional()
+ .describe(
+ 'Set to true to return the preserved messages over the last 3 navigations.',
+ ),
+ includeStackTraces: zod
+ .boolean()
+ .default(false)
+ .optional()
+ .describe(
+ 'Set to true to include the stack trace for each message when available. Increases the response size.',
+ ),
+ serviceWorkerId: zod
+ .string()
+ .optional()
+ .describe(
+ 'Filter messages to only return messages of the specified service worker.',
+ ),
+ },
+ blockedByDialog: false,
+ verifyFilesSchema: {},
+ handler: async (request, response) => {
+ response.setIncludeConsoleData(true, {
+ pageSize: request.params.pageSize,
+ pageIdx: request.params.pageIdx,
+ types: request.params.types,
+ includePreservedMessages: request.params.includePreservedMessages,
+ includeStackTraces: request.params.includeStackTraces,
+ serviceWorkerId: request.params.serviceWorkerId,
+ });
+ },
+ };
+ },
+);
export const getConsoleMessage = definePageTool(() => ({
name: 'get_console_message',
diff --git a/src/tools/lighthouse.ts b/src/tools/lighthouse.ts
index 6ac7479f..07c7add6 100644
--- a/src/tools/lighthouse.ts
+++ b/src/tools/lighthouse.ts
@@ -6,6 +6,8 @@
import path from 'node:path';
+import type {ParsedArguments} from '../config/mcp-options.js';
+
import {
lighthouseRunner,
generateReport,
@@ -19,7 +21,7 @@ import {ToolCategory} from './categories.js';
import {startTrace} from './performance.js';
import {definePageTool} from './ToolDefinition.js';
-export const lighthouseAudit = definePageTool(args => ({
+export const lighthouseAudit = definePageTool((args: ParsedArguments) => ({
name: 'lighthouse_audit',
description: `Get Lighthouse score and reports for accessibility, SEO, best practices, and agentic browsing. This excludes performance. For performance audits, run ${startTrace(args).name}`,
annotations: {
diff --git a/src/tools/pages.ts b/src/tools/pages.ts
index 5d836059..7ed6d125 100644
--- a/src/tools/pages.ts
+++ b/src/tools/pages.ts
@@ -4,6 +4,7 @@
* SPDX-License-Identifier: Apache-2.0
*/
+import type {ParsedArguments} from '../config/mcp-options.js';
import type {CdpPage} from '../third_party/index.js';
import {zod} from '../third_party/index.js';
import {logger} from '../utils/logger.js';
@@ -17,7 +18,7 @@ import {
timeoutSchema,
} from './ToolDefinition.js';
-export const listPages = defineTool(args => {
+export const listPages = defineTool((args: ParsedArguments) => {
return {
name: 'list_pages',
description: `Get a list of pages${args?.categoryExtensions ? ' including extension service workers' : ''} open in the browser.`,
@@ -36,7 +37,7 @@ export const listPages = defineTool(args => {
};
});
-export const selectPage = defineTool(args => ({
+export const selectPage = defineTool((args: ParsedArguments) => ({
name: 'select_page',
description: `Select a page as a context for future tool calls.`,
annotations: {
@@ -97,7 +98,7 @@ export const closePage = defineTool(() => ({
},
}));
-export const newPage = defineTool(args => {
+export const newPage = defineTool((args: ParsedArguments) => {
return {
name: 'new_page',
description: `Open a new tab and load a URL. Use project URL if not specified otherwise.`,
@@ -151,7 +152,7 @@ export const newPage = defineTool(args => {
};
});
-export const navigatePage = definePageTool(args => {
+export const navigatePage = definePageTool((args: ParsedArguments) => {
return {
name: 'navigate_page',
description: `Go to a URL, or back, forward, or reload. Use project URL if not specified otherwise.`,
diff --git a/src/tools/screencast.ts b/src/tools/screencast.ts
index 966f1bf9..82a53bd7 100644
--- a/src/tools/screencast.ts
+++ b/src/tools/screencast.ts
@@ -8,6 +8,7 @@ import fs from 'node:fs/promises';
import os from 'node:os';
import path from 'node:path';
+import type {ParsedArguments} from '../config/mcp-options.js';
import {zod} from '../third_party/index.js';
import type {ScreenRecorder, VideoFormat} from '../third_party/index.js';
@@ -23,7 +24,7 @@ type SupportedVideoExtension = '.webm' | '.mp4';
const supportedExtensions: SupportedVideoExtension[] = ['.webm', '.mp4'];
-export const startScreencast = definePageTool(args => ({
+export const startScreencast = definePageTool((args: ParsedArguments) => ({
name: 'screencast_start',
description: `Starts recording a screencast (video) of the target page in specified format.`,
annotations: {
diff --git a/src/tools/screenshot.ts b/src/tools/screenshot.ts
index fa7ea8de..030e9587 100644
--- a/src/tools/screenshot.ts
+++ b/src/tools/screenshot.ts
@@ -4,6 +4,7 @@
* SPDX-License-Identifier: Apache-2.0
*/
+import type {ParsedArguments} from '../config/mcp-options.js';
import {zod} from '../third_party/index.js';
import type {
BoundingBox,
@@ -122,7 +123,7 @@ function computeDownscaleClip(
};
}
-export const screenshot = definePageTool(args => {
+export const screenshot = definePageTool((args: ParsedArguments) => {
const {
screenshotFormat,
screenshotQuality,
diff --git a/src/tools/script.ts b/src/tools/script.ts
index 7307de42..bcb22ecd 100644
--- a/src/tools/script.ts
+++ b/src/tools/script.ts
@@ -4,6 +4,7 @@
* SPDX-License-Identifier: Apache-2.0
*/
+import type {ParsedArguments} from '../config/mcp-options.js';
import {zod} from '../third_party/index.js';
import type {Frame, JSHandle, Page, WebWorker} from '../third_party/index.js';
import type {ExtensionServiceWorker} from '../types.js';
@@ -14,7 +15,7 @@ import {defineTool, pageIdSchema} from './ToolDefinition.js';
export type Evaluatable = Page | Frame | WebWorker;
-export const evaluateScript = defineTool(cliArgs => {
+export const evaluateScript = defineTool((cliArgs: ParsedArguments) => {
return {
name: 'evaluate_script',
description: `Evaluate a JavaScript function inside the target page${cliArgs.categoryExtensions ? ' or service worker' : ''}. Returns the response as JSON, so returned values have to be JSON-serializable.`,
diff --git a/src/tools/slim/tools.ts b/src/tools/slim/tools.ts
index 5b7e873e..29a7879d 100644
--- a/src/tools/slim/tools.ts
+++ b/src/tools/slim/tools.ts
@@ -4,6 +4,7 @@
* SPDX-License-Identifier: Apache-2.0
*/
+import type {ParsedArguments} from '../../config/mcp-options.js';
import type {Dialog} from '../../third_party/index.js';
import {zod} from '../../third_party/index.js';
import {ToolCategory} from '../categories.js';
@@ -35,7 +36,7 @@ export const screenshot = definePageTool(() => ({
},
}));
-export const navigate = definePageTool(args => {
+export const navigate = definePageTool((args: ParsedArguments) => {
return {
name: 'navigate',
description: `Loads a URL`,