Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions docs/tool-reference.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.

---

Expand Down
8 changes: 5 additions & 3 deletions src/config/cli-options.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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: {
Expand All @@ -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,
},
},
},
Expand Down
10 changes: 5 additions & 5 deletions src/tools/css.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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,
Expand Down
20 changes: 16 additions & 4 deletions tests/tools/css.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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';

Expand All @@ -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(
Expand All @@ -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,
);
Expand All @@ -39,8 +51,8 @@ describe('get_css_styles', () => {
mockStyles,
{
uid: 'element-1',
pageSize: undefined,
pageIdx: undefined,
pageSize: 10,
pageIdx: 0,
},
);
});
Expand Down
Loading