Skip to content

Chrome DevTools for coding agents

fix: reject non-positive resize_page dimensions (#2784)

kevin6ab6d35a3e62
diff --git a/docs/tool-reference.md b/docs/tool-reference.md
index ec83ce30..e0812eb4 100644
--- a/docs/tool-reference.md
+++ b/docs/tool-reference.md
@@ -301,9 +301,9 @@
**Parameters:**
-- **height** (number) **(required)**: Page height
+- **height** (integer) **(required)**: Page height
- **pageId** (number) **(required)**: Targets a specific page by ID.
-- **width** (number) **(required)**: Page width
+- **width** (integer) **(required)**: Page width
---
diff --git a/src/config/cli-options.ts b/src/config/cli-options.ts
index d9c393b2..02ec9f43 100644
--- a/src/config/cli-options.ts
+++ b/src/config/cli-options.ts
@@ -1528,13 +1528,13 @@ export const commands: Commands = {
},
width: {
name: 'width',
- type: 'number',
+ type: 'integer',
description: 'Page width',
required: true,
},
height: {
name: 'height',
- type: 'number',
+ type: 'integer',
description: 'Page height',
required: true,
},
diff --git a/src/tools/pages.ts b/src/tools/pages.ts
index ec84c510..53754b4c 100644
--- a/src/tools/pages.ts
+++ b/src/tools/pages.ts
@@ -323,8 +323,8 @@ export const resizePage = definePageTool(() => ({
readOnlyHint: false,
},
schema: {
- width: zod.number().describe('Page width'),
- height: zod.number().describe('Page height'),
+ width: zod.number().int().positive().describe('Page width'),
+ height: zod.number().int().positive().describe('Page height'),
},
blockedByDialog: false,
verifyFilesSchema: {},
diff --git a/tests/tools/pages.test.ts b/tests/tools/pages.test.ts
index 7355d591..2de07a71 100644
--- a/tests/tools/pages.test.ts
+++ b/tests/tools/pages.test.ts
@@ -22,7 +22,8 @@ import {
handleDialog,
getTabId,
} from '../../src/tools/pages.js';
-import {createMockParsedArguments} from '../mocks.js';
+import {zod} from '../../src/third_party/index.js';
+import {createHandlerMocks, createMockParsedArguments} from '../mocks.js';
import {assertNoServiceWorkerReported, html, withMcpContext} from '../utils.js';
const EXTENSION_SW_PATH = path.join(
@@ -1376,6 +1377,29 @@ describe('pages', () => {
});
});
describe('resize', () => {
+ it('rejects non-positive and fractional dimensions', () => {
+ const {args} = createHandlerMocks();
+ const {width, height} = resizePage(args).schema;
+ const schema = zod.object({width, height});
+ assert.strictEqual(
+ schema.safeParse({width: 800, height: 600}).success,
+ true,
+ );
+ for (const params of [
+ {width: 0, height: 600},
+ {width: 800, height: -1},
+ {width: Number.POSITIVE_INFINITY, height: 600},
+ {width: 800.5, height: 600},
+ {width: 800, height: Number.NaN},
+ ]) {
+ assert.strictEqual(
+ schema.safeParse(params).success,
+ false,
+ JSON.stringify(params),
+ );
+ }
+ });
+
it('resize the page', async () => {
await withMcpContext(async (response, context, args) => {
const page = context.getSelectedMcpPage().pptrPage;