mirror of
https://github.com/ChromeDevTools/chrome-devtools-mcp.git
synced 2026-09-28 11:22:57 +08:00
feat: set default pageSize and pageIdx for get_css_styles tool (#2799)
Sets default page size to 10 and page index to 0
This commit is contained in:
@@ -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.
|
||||
|
||||
---
|
||||
|
||||
|
||||
@@ -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,
|
||||
},
|
||||
},
|
||||
},
|
||||
|
||||
+5
-5
@@ -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,
|
||||
|
||||
+16
-4
@@ -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,
|
||||
},
|
||||
);
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user