Skip to content

Chrome DevTools for coding agents

feat: set default pageSize and pageIdx for get_css_styles tool (#2799)

Samiya Caurdc9d14dc6f08
diff --git a/docs/tool-reference.md b/docs/tool-reference.md
index 5db918be..eb4c01e9 100644
--- a/docs/tool-reference.md
+++ b/docs/tool-reference.md
@@ -404,14 +404,14 @@
### `get_css_styles`
**Description:** Retrieve matched CSS rules, inline styles, inherited styles, and cascade information for an element identified by its UID.
-Use this tool to debug why specific CSS properties are applied, overridden, or conflicting. Supports pagination for elements with many matched rules. Requires a UID from [`take_snapshot`](#take_snapshot).
+Use this tool to debug why specific CSS properties are applied, overridden, or conflicting. Results are paginated and return 10 rules per page by default; use pageIdx to page through the remaining rules. Requires a UID from [`take_snapshot`](#take_snapshot).
**Parameters:**
- **pageId** (number) **(required)**: Targets a specific page by ID.
- **uid** (string) **(required)**: The uid of the element on the page from the page content snapshot to inspect CSS styles for
-- **pageIdx** (integer) _(optional)_: Page number to return (0-based). When omitted, returns the first page.
-- **pageSize** (integer) _(optional)_: Maximum number of CSS rules to return per page. When omitted, returns all rules.
+- **pageIdx** (integer) _(optional)_: Page number to return (0-based). Defaults to 0 (the first page).
+- **pageSize** (integer) _(optional)_: Maximum number of CSS rules to return per page. Defaults to 10.
---
diff --git a/src/config/cli-options.ts b/src/config/cli-options.ts
index 965addaf..586e39ce 100644
--- a/src/config/cli-options.ts
+++ b/src/config/cli-options.ts
@@ -407,7 +407,7 @@ export const commands: Commands = {
},
get_css_styles: {
description:
- 'Retrieve matched CSS rules, inline styles, inherited styles, and cascade information for an element identified by its UID.\nUse this tool to debug why specific CSS properties are applied, overridden, or conflicting. Supports pagination for elements with many matched rules. Requires a UID from take_snapshot.',
+ 'Retrieve matched CSS rules, inline styles, inherited styles, and cascade information for an element identified by its UID.\nUse this tool to debug why specific CSS properties are applied, overridden, or conflicting. Results are paginated and return 10 rules per page by default; use pageIdx to page through the remaining rules. Requires a UID from take_snapshot.',
category: 'Debugging',
args: {
pageId: {
@@ -427,15 +427,17 @@ export const commands: Commands = {
name: 'pageSize',
type: 'integer',
description:
- 'Maximum number of CSS rules to return per page. When omitted, returns all rules.',
+ 'Maximum number of CSS rules to return per page. Defaults to 10.',
required: false,
+ default: 10,
},
pageIdx: {
name: 'pageIdx',
type: 'integer',
description:
- 'Page number to return (0-based). When omitted, returns the first page.',
+ 'Page number to return (0-based). Defaults to 0 (the first page).',
required: false,
+ default: 0,
},
},
},
diff --git a/src/tools/css.ts b/src/tools/css.ts
index d0849e66..e07a102e 100644
--- a/src/tools/css.ts
+++ b/src/tools/css.ts
@@ -12,7 +12,7 @@ import {definePageTool} from './ToolDefinition.js';
export const getCssStyles = definePageTool(() => ({
name: 'get_css_styles',
description: `Retrieve matched CSS rules, inline styles, inherited styles, and cascade information for an element identified by its UID.
-Use this tool to debug why specific CSS properties are applied, overridden, or conflicting. Supports pagination for elements with many matched rules. Requires a UID from take_snapshot.`,
+Use this tool to debug why specific CSS properties are applied, overridden, or conflicting. Results are paginated and return 10 rules per page by default; use pageIdx to page through the remaining rules. Requires a UID from take_snapshot.`,
annotations: {
category: ToolCategory.DEBUGGING,
readOnlyHint: true,
@@ -27,17 +27,17 @@ Use this tool to debug why specific CSS properties are applied, overridden, or c
.number()
.int()
.positive()
- .optional()
+ .default(10)
.describe(
- 'Maximum number of CSS rules to return per page. When omitted, returns all rules.',
+ 'Maximum number of CSS rules to return per page. Defaults to 10.',
),
pageIdx: zod
.number()
.int()
.min(0)
- .optional()
+ .default(0)
.describe(
- 'Page number to return (0-based). When omitted, returns the first page.',
+ 'Page number to return (0-based). Defaults to 0 (the first page).',
),
},
blockedByDialog: true,
diff --git a/tests/tools/css.test.ts b/tests/tools/css.test.ts
index 11cc121a..2b23abbf 100644
--- a/tests/tools/css.test.ts
+++ b/tests/tools/css.test.ts
@@ -4,11 +4,12 @@
* SPDX-License-Identifier: Apache-2.0
*/
+import assert from 'node:assert';
import {afterEach, describe, it} from 'node:test';
import sinon from 'sinon';
-import {DevTools} from '../../src/third_party/index.js';
+import {DevTools, zod} from '../../src/third_party/index.js';
import {getCssStyles} from '../../src/tools/css.js';
import {createHandlerMocks} from '../mocks.js';
@@ -17,6 +18,17 @@ describe('get_css_styles', () => {
sinon.restore();
});
+ it('defaults pagination to the first page of 10 rules', () => {
+ const {args} = createHandlerMocks();
+
+ const params = zod
+ .object(getCssStyles(args).schema)
+ .parse({uid: 'element-1', pageId: 1});
+
+ assert.strictEqual(params.pageSize, 10);
+ assert.strictEqual(params.pageIdx, 0);
+ });
+
it('retrieves matched styles for a uid and passes to response', async () => {
const {page, context, response, args} = createHandlerMocks();
const mockStyles = sinon.createStubInstance(
@@ -25,7 +37,7 @@ describe('get_css_styles', () => {
page.getMatchedStylesForUid.resolves(mockStyles);
await getCssStyles(args).handler(
- {params: {uid: 'element-1'}, page},
+ {params: {uid: 'element-1', pageSize: 10, pageIdx: 0}, page},
response,
context,
);
@@ -39,8 +51,8 @@ describe('get_css_styles', () => {
mockStyles,
{
uid: 'element-1',
- pageSize: undefined,
- pageIdx: undefined,
+ pageSize: 10,
+ pageIdx: 0,
},
);
});