openchrome-mcp 1.6.0 → 1.6.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/chrome/launcher.d.ts.map +1 -1
- package/dist/chrome/launcher.js +1 -3
- package/dist/chrome/launcher.js.map +1 -1
- package/dist/cli/index.js +10 -6
- package/dist/cli/index.js.map +1 -1
- package/dist/hints/rules/composite-suggestions.d.ts.map +1 -1
- package/dist/hints/rules/composite-suggestions.js +28 -1
- package/dist/hints/rules/composite-suggestions.js.map +1 -1
- package/dist/mcp-server.d.ts.map +1 -1
- package/dist/mcp-server.js +4 -2
- package/dist/mcp-server.js.map +1 -1
- package/dist/orchestration/workflow-engine.js +1 -1
- package/dist/orchestration/workflow-engine.js.map +1 -1
- package/dist/router/tool-routing-registry.js +5 -6
- package/dist/router/tool-routing-registry.js.map +1 -1
- package/dist/tools/batch-execute.d.ts.map +1 -1
- package/dist/tools/batch-execute.js +6 -9
- package/dist/tools/batch-execute.js.map +1 -1
- package/dist/tools/batch-paginate.d.ts.map +1 -1
- package/dist/tools/batch-paginate.js +11 -12
- package/dist/tools/batch-paginate.js.map +1 -1
- package/dist/tools/click-element.js +5 -5
- package/dist/tools/click-element.js.map +1 -1
- package/dist/tools/computer.js +3 -3
- package/dist/tools/computer.js.map +1 -1
- package/dist/tools/console-capture.js +3 -3
- package/dist/tools/console-capture.js.map +1 -1
- package/dist/tools/cookies.js +9 -9
- package/dist/tools/cookies.js.map +1 -1
- package/dist/tools/drag-drop.d.ts.map +1 -1
- package/dist/tools/drag-drop.js +9 -10
- package/dist/tools/drag-drop.js.map +1 -1
- package/dist/tools/emulate-device.js +5 -5
- package/dist/tools/emulate-device.js.map +1 -1
- package/dist/tools/file-upload.d.ts.map +1 -1
- package/dist/tools/file-upload.js +1 -2
- package/dist/tools/file-upload.js.map +1 -1
- package/dist/tools/fill-form.js +4 -4
- package/dist/tools/fill-form.js.map +1 -1
- package/dist/tools/find.d.ts.map +1 -1
- package/dist/tools/find.js +2 -2
- package/dist/tools/find.js.map +1 -1
- package/dist/tools/form-input.js +3 -3
- package/dist/tools/form-input.js.map +1 -1
- package/dist/tools/geolocation.js +3 -3
- package/dist/tools/geolocation.js.map +1 -1
- package/dist/tools/http-auth.js +5 -5
- package/dist/tools/http-auth.js.map +1 -1
- package/dist/tools/index.d.ts.map +1 -1
- package/dist/tools/index.js +5 -10
- package/dist/tools/index.js.map +1 -1
- package/dist/tools/inspect.d.ts.map +1 -1
- package/dist/tools/inspect.js +3 -3
- package/dist/tools/inspect.js.map +1 -1
- package/dist/tools/interact.d.ts.map +1 -1
- package/dist/tools/interact.js +5 -5
- package/dist/tools/interact.js.map +1 -1
- package/dist/tools/javascript.d.ts.map +1 -1
- package/dist/tools/javascript.js +4 -4
- package/dist/tools/javascript.js.map +1 -1
- package/dist/tools/lightweight-scroll.d.ts.map +1 -1
- package/dist/tools/lightweight-scroll.js +6 -9
- package/dist/tools/lightweight-scroll.js.map +1 -1
- package/dist/tools/memory.d.ts +7 -4
- package/dist/tools/memory.d.ts.map +1 -1
- package/dist/tools/memory.js +84 -66
- package/dist/tools/memory.js.map +1 -1
- package/dist/tools/navigate.d.ts.map +1 -1
- package/dist/tools/navigate.js +4 -4
- package/dist/tools/navigate.js.map +1 -1
- package/dist/tools/network.d.ts.map +1 -1
- package/dist/tools/network.js +6 -6
- package/dist/tools/network.js.map +1 -1
- package/dist/tools/orchestration.d.ts.map +1 -1
- package/dist/tools/orchestration.js +19 -32
- package/dist/tools/orchestration.js.map +1 -1
- package/dist/tools/page-content.d.ts.map +1 -1
- package/dist/tools/page-content.js +3 -5
- package/dist/tools/page-content.js.map +1 -1
- package/dist/tools/page-pdf.d.ts.map +1 -1
- package/dist/tools/page-pdf.js +14 -16
- package/dist/tools/page-pdf.js.map +1 -1
- package/dist/tools/page-reload.js +2 -2
- package/dist/tools/page-reload.js.map +1 -1
- package/dist/tools/performance-metrics.d.ts.map +1 -1
- package/dist/tools/performance-metrics.js +3 -8
- package/dist/tools/performance-metrics.js.map +1 -1
- package/dist/tools/profile-status.d.ts.map +1 -1
- package/dist/tools/profile-status.js +1 -5
- package/dist/tools/profile-status.js.map +1 -1
- package/dist/tools/query-dom.d.ts +8 -0
- package/dist/tools/query-dom.d.ts.map +1 -0
- package/dist/tools/query-dom.js +421 -0
- package/dist/tools/query-dom.js.map +1 -0
- package/dist/tools/read-page.d.ts.map +1 -1
- package/dist/tools/read-page.js +61 -34
- package/dist/tools/read-page.js.map +1 -1
- package/dist/tools/request-intercept.js +6 -6
- package/dist/tools/request-intercept.js.map +1 -1
- package/dist/tools/shutdown.d.ts.map +1 -1
- package/dist/tools/shutdown.js +2 -5
- package/dist/tools/shutdown.js.map +1 -1
- package/dist/tools/storage.js +4 -4
- package/dist/tools/storage.js.map +1 -1
- package/dist/tools/tabs-close.d.ts.map +1 -1
- package/dist/tools/tabs-close.js +1 -1
- package/dist/tools/tabs-close.js.map +1 -1
- package/dist/tools/tabs-context.d.ts.map +1 -1
- package/dist/tools/tabs-context.js +3 -3
- package/dist/tools/tabs-context.js.map +1 -1
- package/dist/tools/tabs-create.js +3 -3
- package/dist/tools/tabs-create.js.map +1 -1
- package/dist/tools/user-agent.js +3 -3
- package/dist/tools/user-agent.js.map +1 -1
- package/dist/tools/wait-and-click.js +4 -4
- package/dist/tools/wait-and-click.js.map +1 -1
- package/dist/tools/wait-for.js +5 -5
- package/dist/tools/wait-for.js.map +1 -1
- package/dist/tools/worker.d.ts +8 -0
- package/dist/tools/worker.d.ts.map +1 -0
- package/dist/tools/worker.js +160 -0
- package/dist/tools/worker.js.map +1 -0
- package/package.json +1 -1
|
@@ -0,0 +1,421 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* Query DOM Tool - Unified CSS selector and XPath queries
|
|
4
|
+
*
|
|
5
|
+
* Replaces: selector_query, xpath_query
|
|
6
|
+
*/
|
|
7
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
8
|
+
exports.registerQueryDomTool = registerQueryDomTool;
|
|
9
|
+
const session_manager_1 = require("../session-manager");
|
|
10
|
+
// ---------------------------------------------------------------------------
|
|
11
|
+
// Definition
|
|
12
|
+
// ---------------------------------------------------------------------------
|
|
13
|
+
const definition = {
|
|
14
|
+
name: 'query_dom',
|
|
15
|
+
description: 'Query DOM elements via CSS selectors or XPath. Returns tag, attributes, text, and position.',
|
|
16
|
+
inputSchema: {
|
|
17
|
+
type: 'object',
|
|
18
|
+
properties: {
|
|
19
|
+
tabId: {
|
|
20
|
+
type: 'string',
|
|
21
|
+
description: 'Tab ID to query',
|
|
22
|
+
},
|
|
23
|
+
method: {
|
|
24
|
+
type: 'string',
|
|
25
|
+
enum: ['css', 'xpath'],
|
|
26
|
+
description: 'Query method: css or xpath',
|
|
27
|
+
},
|
|
28
|
+
selector: {
|
|
29
|
+
type: 'string',
|
|
30
|
+
description: '(css) CSS selector, e.g. "#search", ".button"',
|
|
31
|
+
},
|
|
32
|
+
xpath: {
|
|
33
|
+
type: 'string',
|
|
34
|
+
description: '(xpath) XPath expression',
|
|
35
|
+
},
|
|
36
|
+
multiple: {
|
|
37
|
+
type: 'boolean',
|
|
38
|
+
description: 'Return all matches. Default: false',
|
|
39
|
+
},
|
|
40
|
+
limit: {
|
|
41
|
+
type: 'number',
|
|
42
|
+
description: '(xpath, multiple) Max results to return',
|
|
43
|
+
},
|
|
44
|
+
},
|
|
45
|
+
required: ['tabId', 'method'],
|
|
46
|
+
},
|
|
47
|
+
};
|
|
48
|
+
// ---------------------------------------------------------------------------
|
|
49
|
+
// CSS handler
|
|
50
|
+
// ---------------------------------------------------------------------------
|
|
51
|
+
async function handleCSS(sessionId, args) {
|
|
52
|
+
const tabId = args.tabId;
|
|
53
|
+
const selector = args.selector;
|
|
54
|
+
const multiple = args.multiple ?? false;
|
|
55
|
+
if (!selector) {
|
|
56
|
+
return {
|
|
57
|
+
content: [{ type: 'text', text: 'Error: selector is required for css method' }],
|
|
58
|
+
isError: true,
|
|
59
|
+
};
|
|
60
|
+
}
|
|
61
|
+
const sessionManager = (0, session_manager_1.getSessionManager)();
|
|
62
|
+
const page = await sessionManager.getPage(sessionId, tabId, undefined, 'query_dom');
|
|
63
|
+
if (!page) {
|
|
64
|
+
return {
|
|
65
|
+
content: [{ type: 'text', text: `Error: Tab ${tabId} not found` }],
|
|
66
|
+
isError: true,
|
|
67
|
+
};
|
|
68
|
+
}
|
|
69
|
+
if (multiple) {
|
|
70
|
+
const elements = await page.$$(selector);
|
|
71
|
+
if (elements.length === 0) {
|
|
72
|
+
return {
|
|
73
|
+
content: [
|
|
74
|
+
{
|
|
75
|
+
type: 'text',
|
|
76
|
+
text: JSON.stringify({
|
|
77
|
+
action: 'query_dom',
|
|
78
|
+
method: 'css',
|
|
79
|
+
selector,
|
|
80
|
+
multiple: true,
|
|
81
|
+
elements: [],
|
|
82
|
+
count: 0,
|
|
83
|
+
message: `No elements found matching "${selector}"`,
|
|
84
|
+
}),
|
|
85
|
+
},
|
|
86
|
+
],
|
|
87
|
+
};
|
|
88
|
+
}
|
|
89
|
+
const MAX_SELECTOR_RESULTS = 50;
|
|
90
|
+
const totalCount = elements.length;
|
|
91
|
+
const limitedElements = elements.slice(0, MAX_SELECTOR_RESULTS);
|
|
92
|
+
const elementInfos = [];
|
|
93
|
+
for (let i = 0; i < limitedElements.length; i++) {
|
|
94
|
+
const element = limitedElements[i];
|
|
95
|
+
const info = await page.evaluate((el, index) => {
|
|
96
|
+
const rect = el.getBoundingClientRect();
|
|
97
|
+
const style = window.getComputedStyle(el);
|
|
98
|
+
const isVisible = style.display !== 'none' &&
|
|
99
|
+
style.visibility !== 'hidden' &&
|
|
100
|
+
style.opacity !== '0' &&
|
|
101
|
+
rect.width > 0 &&
|
|
102
|
+
rect.height > 0;
|
|
103
|
+
const attributes = {};
|
|
104
|
+
for (const attr of el.attributes) {
|
|
105
|
+
attributes[attr.name] = attr.value;
|
|
106
|
+
}
|
|
107
|
+
return {
|
|
108
|
+
ref: `ref_${index}`,
|
|
109
|
+
tagName: el.tagName.toLowerCase(),
|
|
110
|
+
id: el.id || null,
|
|
111
|
+
className: el.className,
|
|
112
|
+
attributes,
|
|
113
|
+
textContent: (el.textContent || '').trim().slice(0, 100),
|
|
114
|
+
isVisible,
|
|
115
|
+
boundingBox: rect.width > 0 && rect.height > 0
|
|
116
|
+
? {
|
|
117
|
+
x: Math.round(rect.x),
|
|
118
|
+
y: Math.round(rect.y),
|
|
119
|
+
width: Math.round(rect.width),
|
|
120
|
+
height: Math.round(rect.height),
|
|
121
|
+
}
|
|
122
|
+
: null,
|
|
123
|
+
};
|
|
124
|
+
}, element, i);
|
|
125
|
+
elementInfos.push(info);
|
|
126
|
+
}
|
|
127
|
+
const result = {
|
|
128
|
+
action: 'query_dom',
|
|
129
|
+
method: 'css',
|
|
130
|
+
selector,
|
|
131
|
+
multiple: true,
|
|
132
|
+
elements: elementInfos,
|
|
133
|
+
count: elementInfos.length,
|
|
134
|
+
};
|
|
135
|
+
if (totalCount > MAX_SELECTOR_RESULTS) {
|
|
136
|
+
result.totalCount = totalCount;
|
|
137
|
+
result.note = `Results limited to first ${MAX_SELECTOR_RESULTS} of ${totalCount} matching elements`;
|
|
138
|
+
}
|
|
139
|
+
return {
|
|
140
|
+
content: [{ type: 'text', text: JSON.stringify(result) }],
|
|
141
|
+
};
|
|
142
|
+
}
|
|
143
|
+
else {
|
|
144
|
+
const element = await page.$(selector);
|
|
145
|
+
if (!element) {
|
|
146
|
+
return {
|
|
147
|
+
content: [
|
|
148
|
+
{
|
|
149
|
+
type: 'text',
|
|
150
|
+
text: JSON.stringify({
|
|
151
|
+
action: 'query_dom',
|
|
152
|
+
method: 'css',
|
|
153
|
+
selector,
|
|
154
|
+
multiple: false,
|
|
155
|
+
element: null,
|
|
156
|
+
message: `No element found matching "${selector}"`,
|
|
157
|
+
}),
|
|
158
|
+
},
|
|
159
|
+
],
|
|
160
|
+
};
|
|
161
|
+
}
|
|
162
|
+
const info = await page.evaluate((el) => {
|
|
163
|
+
const rect = el.getBoundingClientRect();
|
|
164
|
+
const style = window.getComputedStyle(el);
|
|
165
|
+
const isVisible = style.display !== 'none' &&
|
|
166
|
+
style.visibility !== 'hidden' &&
|
|
167
|
+
style.opacity !== '0' &&
|
|
168
|
+
rect.width > 0 &&
|
|
169
|
+
rect.height > 0;
|
|
170
|
+
const attributes = {};
|
|
171
|
+
for (const attr of el.attributes) {
|
|
172
|
+
attributes[attr.name] = attr.value;
|
|
173
|
+
}
|
|
174
|
+
return {
|
|
175
|
+
ref: 'ref_0',
|
|
176
|
+
tagName: el.tagName.toLowerCase(),
|
|
177
|
+
id: el.id || null,
|
|
178
|
+
className: el.className,
|
|
179
|
+
attributes,
|
|
180
|
+
textContent: (el.textContent || '').trim().slice(0, 100),
|
|
181
|
+
isVisible,
|
|
182
|
+
boundingBox: rect.width > 0 && rect.height > 0
|
|
183
|
+
? {
|
|
184
|
+
x: Math.round(rect.x),
|
|
185
|
+
y: Math.round(rect.y),
|
|
186
|
+
width: Math.round(rect.width),
|
|
187
|
+
height: Math.round(rect.height),
|
|
188
|
+
}
|
|
189
|
+
: null,
|
|
190
|
+
};
|
|
191
|
+
}, element);
|
|
192
|
+
return {
|
|
193
|
+
content: [
|
|
194
|
+
{
|
|
195
|
+
type: 'text',
|
|
196
|
+
text: JSON.stringify({
|
|
197
|
+
action: 'query_dom',
|
|
198
|
+
method: 'css',
|
|
199
|
+
selector,
|
|
200
|
+
multiple: false,
|
|
201
|
+
element: info,
|
|
202
|
+
}),
|
|
203
|
+
},
|
|
204
|
+
],
|
|
205
|
+
};
|
|
206
|
+
}
|
|
207
|
+
}
|
|
208
|
+
// ---------------------------------------------------------------------------
|
|
209
|
+
// XPath handler
|
|
210
|
+
// ---------------------------------------------------------------------------
|
|
211
|
+
async function handleXPath(sessionId, args) {
|
|
212
|
+
const tabId = args.tabId;
|
|
213
|
+
const xpath = args.xpath;
|
|
214
|
+
const multiple = args.multiple ?? false;
|
|
215
|
+
const limit = args.limit ?? 50;
|
|
216
|
+
if (!xpath) {
|
|
217
|
+
return {
|
|
218
|
+
content: [{ type: 'text', text: 'Error: xpath is required for xpath method' }],
|
|
219
|
+
isError: true,
|
|
220
|
+
};
|
|
221
|
+
}
|
|
222
|
+
const sessionManager = (0, session_manager_1.getSessionManager)();
|
|
223
|
+
const page = await sessionManager.getPage(sessionId, tabId, undefined, 'query_dom');
|
|
224
|
+
if (!page) {
|
|
225
|
+
return {
|
|
226
|
+
content: [{ type: 'text', text: `Error: Tab ${tabId} not found` }],
|
|
227
|
+
isError: true,
|
|
228
|
+
};
|
|
229
|
+
}
|
|
230
|
+
if (multiple) {
|
|
231
|
+
const result = await page.evaluate((xpathExpr, maxResults) => {
|
|
232
|
+
function extractElementInfo(element, xpathStr) {
|
|
233
|
+
const tagName = element.tagName.toLowerCase();
|
|
234
|
+
const id = element.id || undefined;
|
|
235
|
+
const classNameAttr = element.getAttribute('class');
|
|
236
|
+
const className = classNameAttr || undefined;
|
|
237
|
+
const text = element.textContent?.trim().slice(0, 200) || undefined;
|
|
238
|
+
const attributes = {};
|
|
239
|
+
for (let i = 0; i < element.attributes.length; i++) {
|
|
240
|
+
const attr = element.attributes[i];
|
|
241
|
+
if (attr.name !== 'id' && attr.name !== 'class') {
|
|
242
|
+
attributes[attr.name] = attr.value.slice(0, 100);
|
|
243
|
+
}
|
|
244
|
+
}
|
|
245
|
+
const rect = element.getBoundingClientRect();
|
|
246
|
+
return {
|
|
247
|
+
tagName,
|
|
248
|
+
id,
|
|
249
|
+
className,
|
|
250
|
+
text,
|
|
251
|
+
attributes,
|
|
252
|
+
rect: {
|
|
253
|
+
x: Math.round(rect.x),
|
|
254
|
+
y: Math.round(rect.y),
|
|
255
|
+
width: Math.round(rect.width),
|
|
256
|
+
height: Math.round(rect.height),
|
|
257
|
+
},
|
|
258
|
+
xpath: xpathStr,
|
|
259
|
+
};
|
|
260
|
+
}
|
|
261
|
+
const xpathResult = document.evaluate(xpathExpr, document, null, XPathResult.ORDERED_NODE_SNAPSHOT_TYPE, null);
|
|
262
|
+
const elements = [];
|
|
263
|
+
const count = Math.min(xpathResult.snapshotLength, maxResults);
|
|
264
|
+
for (let i = 0; i < count; i++) {
|
|
265
|
+
const node = xpathResult.snapshotItem(i);
|
|
266
|
+
if (node instanceof Element) {
|
|
267
|
+
const simpleXpath = `(${xpathExpr})[${i + 1}]`;
|
|
268
|
+
elements.push(extractElementInfo(node, simpleXpath));
|
|
269
|
+
}
|
|
270
|
+
}
|
|
271
|
+
return {
|
|
272
|
+
elements,
|
|
273
|
+
totalCount: xpathResult.snapshotLength,
|
|
274
|
+
};
|
|
275
|
+
}, xpath, limit);
|
|
276
|
+
return {
|
|
277
|
+
content: [
|
|
278
|
+
{
|
|
279
|
+
type: 'text',
|
|
280
|
+
text: JSON.stringify({
|
|
281
|
+
action: 'query_dom',
|
|
282
|
+
method: 'xpath',
|
|
283
|
+
xpath,
|
|
284
|
+
multiple: true,
|
|
285
|
+
results: result.elements,
|
|
286
|
+
count: result.elements.length,
|
|
287
|
+
totalCount: result.totalCount,
|
|
288
|
+
message: result.elements.length > 0
|
|
289
|
+
? `Found ${result.totalCount} element(s), returned ${result.elements.length}`
|
|
290
|
+
: 'No elements found',
|
|
291
|
+
}),
|
|
292
|
+
},
|
|
293
|
+
],
|
|
294
|
+
};
|
|
295
|
+
}
|
|
296
|
+
else {
|
|
297
|
+
const element = await page.evaluate((xpathExpr) => {
|
|
298
|
+
function extractElementInfo(el, xpathStr) {
|
|
299
|
+
const tagName = el.tagName.toLowerCase();
|
|
300
|
+
const id = el.id || undefined;
|
|
301
|
+
const classNameAttr = el.getAttribute('class');
|
|
302
|
+
const className = classNameAttr || undefined;
|
|
303
|
+
const text = el.textContent?.trim().slice(0, 200) || undefined;
|
|
304
|
+
const attributes = {};
|
|
305
|
+
for (let i = 0; i < el.attributes.length; i++) {
|
|
306
|
+
const attr = el.attributes[i];
|
|
307
|
+
if (attr.name !== 'id' && attr.name !== 'class') {
|
|
308
|
+
attributes[attr.name] = attr.value.slice(0, 100);
|
|
309
|
+
}
|
|
310
|
+
}
|
|
311
|
+
const rect = el.getBoundingClientRect();
|
|
312
|
+
return {
|
|
313
|
+
tagName,
|
|
314
|
+
id,
|
|
315
|
+
className,
|
|
316
|
+
text,
|
|
317
|
+
attributes,
|
|
318
|
+
rect: {
|
|
319
|
+
x: Math.round(rect.x),
|
|
320
|
+
y: Math.round(rect.y),
|
|
321
|
+
width: Math.round(rect.width),
|
|
322
|
+
height: Math.round(rect.height),
|
|
323
|
+
},
|
|
324
|
+
xpath: xpathStr,
|
|
325
|
+
};
|
|
326
|
+
}
|
|
327
|
+
const xpathResult = document.evaluate(xpathExpr, document, null, XPathResult.FIRST_ORDERED_NODE_TYPE, null);
|
|
328
|
+
const node = xpathResult.singleNodeValue;
|
|
329
|
+
if (!node || !(node instanceof Element)) {
|
|
330
|
+
return null;
|
|
331
|
+
}
|
|
332
|
+
return extractElementInfo(node, xpathExpr);
|
|
333
|
+
}, xpath);
|
|
334
|
+
if (!element) {
|
|
335
|
+
return {
|
|
336
|
+
content: [
|
|
337
|
+
{
|
|
338
|
+
type: 'text',
|
|
339
|
+
text: JSON.stringify({
|
|
340
|
+
action: 'query_dom',
|
|
341
|
+
method: 'xpath',
|
|
342
|
+
xpath,
|
|
343
|
+
multiple: false,
|
|
344
|
+
result: null,
|
|
345
|
+
message: 'No element found matching XPath',
|
|
346
|
+
}),
|
|
347
|
+
},
|
|
348
|
+
],
|
|
349
|
+
};
|
|
350
|
+
}
|
|
351
|
+
return {
|
|
352
|
+
content: [
|
|
353
|
+
{
|
|
354
|
+
type: 'text',
|
|
355
|
+
text: JSON.stringify({
|
|
356
|
+
action: 'query_dom',
|
|
357
|
+
method: 'xpath',
|
|
358
|
+
xpath,
|
|
359
|
+
multiple: false,
|
|
360
|
+
result: element,
|
|
361
|
+
message: `Found element: <${element.tagName}${element.id ? ` id="${element.id}"` : ''}>`,
|
|
362
|
+
}),
|
|
363
|
+
},
|
|
364
|
+
],
|
|
365
|
+
};
|
|
366
|
+
}
|
|
367
|
+
}
|
|
368
|
+
// ---------------------------------------------------------------------------
|
|
369
|
+
// Router
|
|
370
|
+
// ---------------------------------------------------------------------------
|
|
371
|
+
const handler = async (sessionId, args) => {
|
|
372
|
+
const tabId = args.tabId;
|
|
373
|
+
const method = args.method;
|
|
374
|
+
if (!tabId) {
|
|
375
|
+
return {
|
|
376
|
+
content: [{ type: 'text', text: 'Error: tabId is required' }],
|
|
377
|
+
isError: true,
|
|
378
|
+
};
|
|
379
|
+
}
|
|
380
|
+
try {
|
|
381
|
+
switch (method) {
|
|
382
|
+
case 'css':
|
|
383
|
+
return await handleCSS(sessionId, args);
|
|
384
|
+
case 'xpath':
|
|
385
|
+
return await handleXPath(sessionId, args);
|
|
386
|
+
default:
|
|
387
|
+
return {
|
|
388
|
+
content: [
|
|
389
|
+
{
|
|
390
|
+
type: 'text',
|
|
391
|
+
text: `Error: Unknown method "${method}". Use "css" or "xpath".`,
|
|
392
|
+
},
|
|
393
|
+
],
|
|
394
|
+
isError: true,
|
|
395
|
+
};
|
|
396
|
+
}
|
|
397
|
+
}
|
|
398
|
+
catch (error) {
|
|
399
|
+
const errorMessage = error instanceof Error ? error.message : String(error);
|
|
400
|
+
// Check for XPath syntax errors
|
|
401
|
+
if (method === 'xpath' && (errorMessage.includes('XPath') || errorMessage.includes('syntax'))) {
|
|
402
|
+
return {
|
|
403
|
+
content: [{ type: 'text', text: `XPath syntax error: ${errorMessage}` }],
|
|
404
|
+
isError: true,
|
|
405
|
+
};
|
|
406
|
+
}
|
|
407
|
+
return {
|
|
408
|
+
content: [
|
|
409
|
+
{
|
|
410
|
+
type: 'text',
|
|
411
|
+
text: `DOM query error: ${errorMessage}`,
|
|
412
|
+
},
|
|
413
|
+
],
|
|
414
|
+
isError: true,
|
|
415
|
+
};
|
|
416
|
+
}
|
|
417
|
+
};
|
|
418
|
+
function registerQueryDomTool(server) {
|
|
419
|
+
server.registerTool('query_dom', handler, definition);
|
|
420
|
+
}
|
|
421
|
+
//# sourceMappingURL=query-dom.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"query-dom.js","sourceRoot":"","sources":["../../src/tools/query-dom.ts"],"names":[],"mappings":";AAAA;;;;GAIG;;AAogBH,oDAEC;AAlgBD,wDAAuD;AA2BvD,8EAA8E;AAC9E,aAAa;AACb,8EAA8E;AAE9E,MAAM,UAAU,GAAsB;IACpC,IAAI,EAAE,WAAW;IACjB,WAAW,EACT,6FAA6F;IAC/F,WAAW,EAAE;QACX,IAAI,EAAE,QAAQ;QACd,UAAU,EAAE;YACV,KAAK,EAAE;gBACL,IAAI,EAAE,QAAQ;gBACd,WAAW,EAAE,iBAAiB;aAC/B;YACD,MAAM,EAAE;gBACN,IAAI,EAAE,QAAQ;gBACd,IAAI,EAAE,CAAC,KAAK,EAAE,OAAO,CAAC;gBACtB,WAAW,EAAE,4BAA4B;aAC1C;YACD,QAAQ,EAAE;gBACR,IAAI,EAAE,QAAQ;gBACd,WAAW,EAAE,+CAA+C;aAC7D;YACD,KAAK,EAAE;gBACL,IAAI,EAAE,QAAQ;gBACd,WAAW,EAAE,0BAA0B;aACxC;YACD,QAAQ,EAAE;gBACR,IAAI,EAAE,SAAS;gBACf,WAAW,EAAE,oCAAoC;aAClD;YACD,KAAK,EAAE;gBACL,IAAI,EAAE,QAAQ;gBACd,WAAW,EAAE,yCAAyC;aACvD;SACF;QACD,QAAQ,EAAE,CAAC,OAAO,EAAE,QAAQ,CAAC;KAC9B;CACF,CAAC;AAEF,8EAA8E;AAC9E,cAAc;AACd,8EAA8E;AAE9E,KAAK,UAAU,SAAS,CACtB,SAAiB,EACjB,IAA6B;IAE7B,MAAM,KAAK,GAAG,IAAI,CAAC,KAAe,CAAC;IACnC,MAAM,QAAQ,GAAG,IAAI,CAAC,QAAkB,CAAC;IACzC,MAAM,QAAQ,GAAI,IAAI,CAAC,QAAoB,IAAI,KAAK,CAAC;IAErD,IAAI,CAAC,QA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BACjE;qBACF;oBACD,OAAO,EAAE,IAAI;iBACd,CAAC;QACN,CAAC;IACH,CAAC;IAAC,OAAO,KAAK,EAAE,CAAC;QACf,MAAM,YAAY,GAAG,KAAK,YAAY,KAAK,CAAC,CAAC,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC;QAE5E,gCAAgC;QAChC,IAAI,MAAM,KAAK,OAAO,IAAI,CAAC,YAAY,CAAC,QAAQ,CAAC,OAAO,CAAC,IAAI,YAAY,CAAC,QAAQ,CAAC,QAAQ,CAAC,CAAC,EAAE,CAAC;YAC9F,OAAO;gBACL,OAAO,EAAE,CAAC,EAAE,IAAI,EAAE,MAAM,EAAE,IAAI,EAAE,uBAAuB,YAAY,EAAE,EAAE,CAAC;gBACxE,OAAO,EAAE,IAAI;aACd,CAAC;QACJ,CAAC;QAED,OAAO;YACL,OAAO,EAAE;gBACP;oBACE,IAAI,EAAE,MAAM;oBACZ,IAAI,EAAE,oBAAoB,YAAY,EAAE;iBACzC;aACF;YACD,OAAO,EAAE,IAAI;SACd,CAAC;IACJ,CAAC;AACH,CAAC,CAAC;AAEF,SAAgB,oBAAoB,CAAC,MAAiB;IACpD,MAAM,CAAC,YAAY,CAAC,WAAW,EAAE,OAAO,EAAE,UAAU,CAAC,CAAC;AACxD,CAAC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"read-page.d.ts","sourceRoot":"","sources":["../../src/tools/read-page.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,OAAO,EAAE,SAAS,EAAE,MAAM,eAAe,CAAC;
|
|
1
|
+
{"version":3,"file":"read-page.d.ts","sourceRoot":"","sources":["../../src/tools/read-page.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,OAAO,EAAE,SAAS,EAAE,MAAM,eAAe,CAAC;AAugB1C,wBAAgB,oBAAoB,CAAC,MAAM,EAAE,SAAS,GAAG,IAAI,CAE5D"}
|
package/dist/tools/read-page.js
CHANGED
|
@@ -25,7 +25,7 @@ function formatPaginationSection(pagination) {
|
|
|
25
25
|
}
|
|
26
26
|
const definition = {
|
|
27
27
|
name: 'read_page',
|
|
28
|
-
description: 'Get page content
|
|
28
|
+
description: 'Get page content as compact DOM (default), accessibility tree (ax), or CSS diagnostics (css). Use css mode BEFORE javascript_tool for style inspection.',
|
|
29
29
|
inputSchema: {
|
|
30
30
|
type: 'object',
|
|
31
31
|
properties: {
|
|
@@ -35,29 +35,29 @@ const definition = {
|
|
|
35
35
|
},
|
|
36
36
|
depth: {
|
|
37
37
|
type: 'number',
|
|
38
|
-
description: '
|
|
38
|
+
description: 'Max tree depth. Default: 8 (all), 5 (interactive)',
|
|
39
39
|
},
|
|
40
40
|
filter: {
|
|
41
41
|
type: 'string',
|
|
42
42
|
enum: ['interactive', 'all'],
|
|
43
|
-
description: 'Filter
|
|
43
|
+
description: 'Filter: "interactive" for buttons/links/inputs only',
|
|
44
44
|
},
|
|
45
45
|
ref_id: {
|
|
46
46
|
type: 'string',
|
|
47
|
-
description: '
|
|
47
|
+
description: 'Parent element ref for subtree scoping',
|
|
48
48
|
},
|
|
49
49
|
selector: {
|
|
50
50
|
type: 'string',
|
|
51
|
-
description: '
|
|
51
|
+
description: 'CSS selector to inspect (css mode only)',
|
|
52
52
|
},
|
|
53
53
|
mode: {
|
|
54
54
|
type: 'string',
|
|
55
55
|
enum: ['ax', 'dom', 'css'],
|
|
56
|
-
description: 'Output mode:
|
|
56
|
+
description: 'Output mode: dom (default), ax, or css',
|
|
57
57
|
},
|
|
58
58
|
includePagination: {
|
|
59
59
|
type: 'boolean',
|
|
60
|
-
description: '
|
|
60
|
+
description: 'Include pagination info. Default: true',
|
|
61
61
|
},
|
|
62
62
|
},
|
|
63
63
|
required: ['tabId'],
|
|
@@ -87,7 +87,7 @@ const handler = async (sessionId, args) => {
|
|
|
87
87
|
}
|
|
88
88
|
const cdpClient = sessionManager.getCDPClient();
|
|
89
89
|
// Mode dispatch
|
|
90
|
-
const mode = args.mode || '
|
|
90
|
+
const mode = args.mode || 'dom';
|
|
91
91
|
if (mode !== 'ax' && mode !== 'dom' && mode !== 'css') {
|
|
92
92
|
return {
|
|
93
93
|
content: [{ type: 'text', text: `Error: Invalid mode "${mode}". Must be "ax", "dom", or "css".` }],
|
|
@@ -250,22 +250,27 @@ const handler = async (sessionId, args) => {
|
|
|
250
250
|
};
|
|
251
251
|
}
|
|
252
252
|
if (mode === 'dom') {
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
253
|
+
try {
|
|
254
|
+
const refId = args.ref_id;
|
|
255
|
+
const depth = args.depth;
|
|
256
|
+
const result = await (0, dom_1.serializeDOM)(page, cdpClient, {
|
|
257
|
+
maxDepth: depth ?? -1,
|
|
258
|
+
filter: filter,
|
|
259
|
+
interactiveOnly: filter === 'interactive',
|
|
260
|
+
});
|
|
261
|
+
let outputText = result.content;
|
|
262
|
+
if (refId) {
|
|
263
|
+
outputText = '[Note: ref_id is ignored in DOM mode. Use mode "ax" for subtree scoping.]\n\n' + outputText;
|
|
264
|
+
}
|
|
265
|
+
const includePaginationDom = args.includePagination !== false;
|
|
266
|
+
const domPaginationSection = includePaginationDom ? formatPaginationSection(await (0, pagination_detector_1.detectPagination)(page, tabId)) : '';
|
|
267
|
+
return {
|
|
268
|
+
content: [{ type: 'text', text: outputText + domPaginationSection }],
|
|
269
|
+
};
|
|
270
|
+
}
|
|
271
|
+
catch {
|
|
272
|
+
// DOM serialization failed — fall through to AX mode as fallback
|
|
263
273
|
}
|
|
264
|
-
const includePaginationDom = args.includePagination !== false;
|
|
265
|
-
const domPaginationSection = includePaginationDom ? formatPaginationSection(await (0, pagination_detector_1.detectPagination)(page, tabId)) : '';
|
|
266
|
-
return {
|
|
267
|
-
content: [{ type: 'text', text: outputText + domPaginationSection }],
|
|
268
|
-
};
|
|
269
274
|
}
|
|
270
275
|
// Resolve ref_id to backendDOMNodeId if provided (AX mode subtree scoping)
|
|
271
276
|
const refIdParam = args.ref_id;
|
|
@@ -402,17 +407,39 @@ const handler = async (sessionId, args) => {
|
|
|
402
407
|
const includePaginationAx = args.includePagination !== false;
|
|
403
408
|
const axPaginationSection = includePaginationAx ? formatPaginationSection(await (0, pagination_detector_1.detectPagination)(page, tabId)) : '';
|
|
404
409
|
if (charCount > MAX_OUTPUT) {
|
|
405
|
-
|
|
406
|
-
|
|
407
|
-
|
|
408
|
-
|
|
409
|
-
|
|
410
|
-
|
|
411
|
-
|
|
412
|
-
|
|
413
|
-
|
|
414
|
-
|
|
415
|
-
|
|
410
|
+
// Auto-fallback: DOM mode produces complete output at ~5-10x fewer tokens
|
|
411
|
+
try {
|
|
412
|
+
const domResult = await (0, dom_1.serializeDOM)(page, cdpClient, {
|
|
413
|
+
maxDepth: -1,
|
|
414
|
+
filter: filter,
|
|
415
|
+
interactiveOnly: filter === 'interactive',
|
|
416
|
+
});
|
|
417
|
+
const fallbackNote = '\n\n[AX tree exceeded output limit (' + charCount + ' chars). ' +
|
|
418
|
+
'Auto-switched to DOM mode for complete output. ' +
|
|
419
|
+
'Use mode: "ax" with ref_id to scope specific subtrees for AX format.]';
|
|
420
|
+
return {
|
|
421
|
+
content: [
|
|
422
|
+
{
|
|
423
|
+
type: 'text',
|
|
424
|
+
text: domResult.content + fallbackNote + axPaginationSection,
|
|
425
|
+
},
|
|
426
|
+
],
|
|
427
|
+
};
|
|
428
|
+
}
|
|
429
|
+
catch {
|
|
430
|
+
// If DOM serialization fails, fall back to truncated AX (original behavior)
|
|
431
|
+
return {
|
|
432
|
+
content: [
|
|
433
|
+
{
|
|
434
|
+
type: 'text',
|
|
435
|
+
text: pageStatsLine +
|
|
436
|
+
output +
|
|
437
|
+
'\n\n[Output truncated. Try mode: "dom" for ~5-10x fewer tokens, or use smaller depth / ref_id to focus on specific element.]' +
|
|
438
|
+
axPaginationSection,
|
|
439
|
+
},
|
|
440
|
+
],
|
|
441
|
+
};
|
|
442
|
+
}
|
|
416
443
|
}
|
|
417
444
|
return {
|
|
418
445
|
content: [{ type: 'text', text: pageStatsLine + output + axPaginationSection }],
|