@pyrokine/mcp-chrome 3.0.1 → 3.1.0

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.
Files changed (144) hide show
  1. package/README.md +678 -341
  2. package/README_zh.md +694 -291
  3. package/dist/cdp/client.d.ts +7 -3
  4. package/dist/cdp/client.d.ts.map +1 -1
  5. package/dist/cdp/client.js +252 -63
  6. package/dist/cdp/client.js.map +1 -1
  7. package/dist/cdp/launcher.d.ts +1 -1
  8. package/dist/cdp/launcher.d.ts.map +1 -1
  9. package/dist/cdp/launcher.js +33 -12
  10. package/dist/cdp/launcher.js.map +1 -1
  11. package/dist/core/auto-wait.d.ts.map +1 -1
  12. package/dist/core/auto-wait.js +88 -52
  13. package/dist/core/auto-wait.js.map +1 -1
  14. package/dist/core/browser-driver.d.ts +72 -15
  15. package/dist/core/browser-driver.d.ts.map +1 -1
  16. package/dist/core/browser-driver.js.map +1 -1
  17. package/dist/core/browser-event-schema.d.ts +287 -0
  18. package/dist/core/browser-event-schema.d.ts.map +1 -0
  19. package/dist/core/browser-event-schema.js +104 -0
  20. package/dist/core/browser-event-schema.js.map +1 -0
  21. package/dist/core/browser-events.d.ts +99 -0
  22. package/dist/core/browser-events.d.ts.map +1 -0
  23. package/dist/core/browser-events.js +1312 -0
  24. package/dist/core/browser-events.js.map +1 -0
  25. package/dist/core/challenge-page.d.ts +39 -0
  26. package/dist/core/challenge-page.d.ts.map +1 -0
  27. package/dist/core/challenge-page.js +226 -0
  28. package/dist/core/challenge-page.js.map +1 -0
  29. package/dist/core/dom-helpers.d.ts +28 -0
  30. package/dist/core/dom-helpers.d.ts.map +1 -0
  31. package/dist/core/dom-helpers.js +311 -0
  32. package/dist/core/dom-helpers.js.map +1 -0
  33. package/dist/core/errors.d.ts +4 -0
  34. package/dist/core/errors.d.ts.map +1 -1
  35. package/dist/core/errors.js +51 -7
  36. package/dist/core/errors.js.map +1 -1
  37. package/dist/core/file-upload.d.ts +22 -0
  38. package/dist/core/file-upload.d.ts.map +1 -0
  39. package/dist/core/file-upload.js +194 -0
  40. package/dist/core/file-upload.js.map +1 -0
  41. package/dist/core/locator.d.ts +10 -2
  42. package/dist/core/locator.d.ts.map +1 -1
  43. package/dist/core/locator.js +121 -200
  44. package/dist/core/locator.js.map +1 -1
  45. package/dist/core/os-mouse.d.ts +11 -0
  46. package/dist/core/os-mouse.d.ts.map +1 -1
  47. package/dist/core/os-mouse.js +102 -29
  48. package/dist/core/os-mouse.js.map +1 -1
  49. package/dist/core/retry.d.ts.map +1 -1
  50. package/dist/core/retry.js +4 -1
  51. package/dist/core/retry.js.map +1 -1
  52. package/dist/core/session.d.ts +61 -12
  53. package/dist/core/session.d.ts.map +1 -1
  54. package/dist/core/session.js +1040 -259
  55. package/dist/core/session.js.map +1 -1
  56. package/dist/core/types.d.ts +5 -1
  57. package/dist/core/types.d.ts.map +1 -1
  58. package/dist/core/types.js +16 -1
  59. package/dist/core/types.js.map +1 -1
  60. package/dist/core/unified-session.d.ts +41 -35
  61. package/dist/core/unified-session.d.ts.map +1 -1
  62. package/dist/core/unified-session.js +872 -263
  63. package/dist/core/unified-session.js.map +1 -1
  64. package/dist/core/utils.d.ts +5 -4
  65. package/dist/core/utils.d.ts.map +1 -1
  66. package/dist/core/utils.js +73 -18
  67. package/dist/core/utils.js.map +1 -1
  68. package/dist/extension/bridge.d.ts +48 -17
  69. package/dist/extension/bridge.d.ts.map +1 -1
  70. package/dist/extension/bridge.js +239 -37
  71. package/dist/extension/bridge.js.map +1 -1
  72. package/dist/extension/http-server.d.ts +7 -2
  73. package/dist/extension/http-server.d.ts.map +1 -1
  74. package/dist/extension/http-server.js +211 -49
  75. package/dist/extension/http-server.js.map +1 -1
  76. package/dist/index.js +14 -1
  77. package/dist/index.js.map +1 -1
  78. package/dist/tools/browse.d.ts.map +1 -1
  79. package/dist/tools/browse.js +56 -28
  80. package/dist/tools/browse.js.map +1 -1
  81. package/dist/tools/browser-event-output.d.ts +7 -0
  82. package/dist/tools/browser-event-output.d.ts.map +1 -0
  83. package/dist/tools/browser-event-output.js +19 -0
  84. package/dist/tools/browser-event-output.js.map +1 -0
  85. package/dist/tools/challenge.d.ts +17 -5
  86. package/dist/tools/challenge.d.ts.map +1 -1
  87. package/dist/tools/challenge.js +110 -189
  88. package/dist/tools/challenge.js.map +1 -1
  89. package/dist/tools/cookies.d.ts.map +1 -1
  90. package/dist/tools/cookies.js +33 -8
  91. package/dist/tools/cookies.js.map +1 -1
  92. package/dist/tools/diagnostics.d.ts.map +1 -1
  93. package/dist/tools/diagnostics.js +14 -0
  94. package/dist/tools/diagnostics.js.map +1 -1
  95. package/dist/tools/evaluate.d.ts +6 -5
  96. package/dist/tools/evaluate.d.ts.map +1 -1
  97. package/dist/tools/evaluate.js +92 -52
  98. package/dist/tools/evaluate.js.map +1 -1
  99. package/dist/tools/extract.d.ts.map +1 -1
  100. package/dist/tools/extract.js +149 -103
  101. package/dist/tools/extract.js.map +1 -1
  102. package/dist/tools/input.d.ts.map +1 -1
  103. package/dist/tools/input.js +555 -229
  104. package/dist/tools/input.js.map +1 -1
  105. package/dist/tools/logs.d.ts.map +1 -1
  106. package/dist/tools/logs.js +50 -11
  107. package/dist/tools/logs.js.map +1 -1
  108. package/dist/tools/manage.d.ts.map +1 -1
  109. package/dist/tools/manage.js +111 -16
  110. package/dist/tools/manage.js.map +1 -1
  111. package/dist/tools/network-sanitizer.d.ts +1 -0
  112. package/dist/tools/network-sanitizer.d.ts.map +1 -1
  113. package/dist/tools/network-sanitizer.js +30 -1
  114. package/dist/tools/network-sanitizer.js.map +1 -1
  115. package/dist/tools/page-context.d.ts +4 -3
  116. package/dist/tools/page-context.d.ts.map +1 -1
  117. package/dist/tools/page-context.js +56 -14
  118. package/dist/tools/page-context.js.map +1 -1
  119. package/dist/tools/post-condition.d.ts +1 -1
  120. package/dist/tools/post-condition.d.ts.map +1 -1
  121. package/dist/tools/post-condition.js +136 -44
  122. package/dist/tools/post-condition.js.map +1 -1
  123. package/dist/tools/schema.d.ts +7 -4
  124. package/dist/tools/schema.d.ts.map +1 -1
  125. package/dist/tools/schema.js +32 -122
  126. package/dist/tools/schema.js.map +1 -1
  127. package/dist/tools/target-diagnostics.d.ts +3 -3
  128. package/dist/tools/target-diagnostics.d.ts.map +1 -1
  129. package/dist/tools/target-diagnostics.js +17 -7
  130. package/dist/tools/target-diagnostics.js.map +1 -1
  131. package/dist/tools/wait.d.ts.map +1 -1
  132. package/dist/tools/wait.js +94 -40
  133. package/dist/tools/wait.js.map +1 -1
  134. package/extension/dist/assets/{content.ts-qe6IB5DK.js → content.ts-BAMOcF3R.js} +1 -1
  135. package/extension/dist/assets/{content.ts-loader-DUWbDHRS.js → content.ts-loader-4F9a1EWZ.js} +1 -1
  136. package/extension/dist/assets/index.ts-B79g2ikq.js +19820 -0
  137. package/extension/dist/assets/{page-scripts-D508WLkW.js → page-scripts-CSxn58h1.js} +257 -366
  138. package/extension/dist/assets/{popup.html-B-eVq48O.js → popup.html-DwwHo00N.js} +2 -2
  139. package/extension/dist/manifest.json +4 -4
  140. package/extension/dist/service-worker-loader.js +1 -1
  141. package/extension/dist/src/popup/popup.html +3 -3
  142. package/package.json +8 -6
  143. package/scripts/start-chrome.ps1 +9 -1
  144. package/extension/dist/assets/index.ts-D7_LCUoV.js +0 -9319
@@ -1,4 +1,43 @@
1
1
  //#region src/background/page-scripts.ts
2
+ function observeNativePointer(operation, id, deadline) {
3
+ const scope = globalThis;
4
+ if (operation === "start") {
5
+ scope.__mcpNativePointer?.stop();
6
+ const listener = (event) => {
7
+ if (event.isTrusted && scope.__mcpNativePointer?.id === id) {
8
+ scope.__mcpNativePointer.sample = {
9
+ at: Date.now(),
10
+ previousAt: scope.__mcpNativePointer.sample?.at,
11
+ sameTarget: scope.__mcpNativePointer.target === event.target,
12
+ clientX: event.clientX,
13
+ clientY: event.clientY,
14
+ screenX: event.screenX,
15
+ screenY: event.screenY,
16
+ scale: window.devicePixelRatio || 1
17
+ };
18
+ scope.__mcpNativePointer.target = event.target;
19
+ }
20
+ };
21
+ const stop = () => {
22
+ removeEventListener("pointermove", listener, true);
23
+ clearTimeout(timer);
24
+ if (scope.__mcpNativePointer?.id === id) delete scope.__mcpNativePointer;
25
+ };
26
+ const timer = setTimeout(stop, Math.max(0, deadline - Date.now()));
27
+ scope.__mcpNativePointer = {
28
+ id,
29
+ stop
30
+ };
31
+ addEventListener("pointermove", listener, true);
32
+ }
33
+ const current = scope.__mcpNativePointer;
34
+ if (current?.id !== id) return { active: false };
35
+ if (operation === "stop") current.stop();
36
+ return {
37
+ active: true,
38
+ sample: current.sample
39
+ };
40
+ }
2
41
  function installFrameProbeListener() {
3
42
  const probeWindow = window;
4
43
  if (probeWindow.__mcpFrameProbeListenerV2) return;
@@ -39,85 +78,24 @@ function generateAccessibilityTree(filter, maxDepth, maxLength, refId, expectedU
39
78
  win.__mcpRefCounter = win.__mcpRefCounter || 0;
40
79
  const lines = [];
41
80
  function getRole(element) {
42
- const role = element.getAttribute("role");
43
- if (role) return role;
44
- const tag = element.tagName.toLowerCase();
45
- const type = element.getAttribute("type");
46
- return {
47
- a: "link",
48
- button: "button",
49
- input: type === "submit" || type === "button" ? "button" : type === "checkbox" ? "checkbox" : type === "radio" ? "radio" : type === "file" ? "button" : "textbox",
50
- select: "combobox",
51
- textarea: "textbox",
52
- h1: "heading",
53
- h2: "heading",
54
- h3: "heading",
55
- h4: "heading",
56
- h5: "heading",
57
- h6: "heading",
58
- img: "image",
59
- nav: "navigation",
60
- main: "main",
61
- header: "banner",
62
- footer: "contentinfo",
63
- section: "region",
64
- article: "article",
65
- aside: "complementary",
66
- form: "form",
67
- table: "table",
68
- ul: "list",
69
- ol: "list",
70
- li: "listitem",
71
- label: "label"
72
- }[tag] || "generic";
81
+ return globalThis.__mcpDomHelpers.role(element);
73
82
  }
74
83
  function getName(element) {
75
- const tag = element.tagName.toLowerCase();
76
- if (tag === "select") {
77
- const select = element;
78
- const selected = select.querySelector("option[selected]") || select.options[select.selectedIndex];
79
- if (selected?.textContent) return selected.textContent.trim();
80
- }
81
- const ariaLabel = element.getAttribute("aria-label");
82
- if (ariaLabel?.trim()) return ariaLabel.trim();
83
- const placeholder = element.getAttribute("placeholder");
84
- if (placeholder?.trim()) return placeholder.trim();
85
- const title = element.getAttribute("title");
86
- if (title?.trim()) return title.trim();
87
- const alt = element.getAttribute("alt");
88
- if (alt?.trim()) return alt.trim();
89
- if (element.id) {
90
- const label = document.querySelector(`label[for="${CSS.escape(element.id)}"]`);
91
- if (label?.textContent?.trim()) return label.textContent.trim();
92
- }
93
- if (tag === "input") {
94
- const input = element;
95
- const inputType = input.type || "";
96
- if (inputType !== "hidden" && inputType !== "password") {
97
- const value = input.value;
98
- if (value && (inputType === "submit" || value.length < 50)) return value.trim();
99
- }
100
- }
84
+ return globalThis.__mcpDomHelpers.accessibleName(element, filter === "all");
85
+ }
86
+ function currentValue(element, name) {
87
+ if (element.tagName.toLowerCase() !== "input") return;
88
+ const input = element;
101
89
  if ([
90
+ "hidden",
91
+ "password",
92
+ "file"
93
+ ].includes(input.type) || name && [
102
94
  "button",
103
- "a",
104
- "summary"
105
- ].includes(tag)) {
106
- let text = "";
107
- for (const child of element.childNodes) if (child.nodeType === Node.TEXT_NODE) text += child.textContent;
108
- if (text.trim()) return text.trim();
109
- }
110
- if (tag.match(/^h[1-6]$/)) {
111
- const text = element.textContent;
112
- if (text?.trim()) return text.trim().substring(0, 100);
113
- }
114
- let textContent = "";
115
- for (const child of element.childNodes) if (child.nodeType === Node.TEXT_NODE) textContent += child.textContent;
116
- if (textContent.trim().length >= 3) {
117
- const trimmed = textContent.trim();
118
- return trimmed.length > 100 ? trimmed.substring(0, 100) + "..." : trimmed;
119
- }
120
- return "";
95
+ "submit",
96
+ "reset"
97
+ ].includes(input.type)) return;
98
+ return input.value;
121
99
  }
122
100
  function isVisible(element) {
123
101
  const style = window.getComputedStyle(element);
@@ -210,17 +188,18 @@ function generateAccessibilityTree(filter, maxDepth, maxLength, refId, expectedU
210
188
  function isCovered(element) {
211
189
  const rect = element.getBoundingClientRect();
212
190
  if (rect.width <= 0 || rect.height <= 0) return false;
213
- const hit = document.elementFromPoint(rect.x + rect.width / 2, rect.y + rect.height / 2);
214
- return Boolean(hit && hit !== element && !element.contains(hit) && !hit.contains(element));
191
+ const hit = globalThis.__mcpDomHelpers.deepElementFromPoint(rect.x + rect.width / 2, rect.y + rect.height / 2);
192
+ return Boolean(hit && !globalThis.__mcpDomHelpers.containsComposed(element, hit));
215
193
  }
216
194
  const interactiveElements = [];
217
- function rememberInteractive(element, elementRefId, role, name) {
195
+ function rememberInteractive(element, elementRefId, role, name, value) {
218
196
  if (!isInteractive(element) || interactiveElements.length >= 100) return;
219
197
  const rect = element.getBoundingClientRect();
220
198
  interactiveElements.push({
221
199
  refId: elementRefId,
222
200
  role,
223
201
  name,
202
+ ...value !== void 0 ? { value } : {},
224
203
  selector: cssSelector(element),
225
204
  visible: isVisible(element),
226
205
  disabled: isDisabled(element),
@@ -233,35 +212,50 @@ function generateAccessibilityTree(filter, maxDepth, maxLength, refId, expectedU
233
212
  covered: isCovered(element)
234
213
  });
235
214
  }
236
- function traverse(element, level, checkRefId) {
237
- if (level > maxDepth || !element || !element.tagName) return;
238
- const include = shouldInclude(element, checkRefId) || checkRefId && level === 0;
239
- if (include) {
240
- const role = getRole(element);
241
- const name = getName(element);
242
- const elementRefId = getOrCreateRef(element);
243
- let line = " ".repeat(level) + role;
244
- if (name) line += ` "${name.replace(/\s+/g, " ").replace(/"/g, "\\\"")}"`;
245
- line += ` [${elementRefId}]`;
246
- const href = element.getAttribute("href");
247
- if (href) line += ` href="${href}"`;
248
- const type = element.getAttribute("type");
249
- if (type) line += ` type="${type}"`;
250
- lines.push(line);
251
- rememberInteractive(element, elementRefId, role, name);
252
- if (element.tagName.toLowerCase() === "select") {
253
- const select = element;
254
- for (const option of select.options) {
255
- let optLine = " ".repeat(level + 1) + "option";
256
- const optText = option.textContent?.trim() || "";
257
- if (optText) optLine += ` "${optText.replace(/\s+/g, " ").substring(0, 100).replace(/"/g, "\\\"")}"`;
258
- if (option.selected) optLine += " (selected)";
259
- if (option.value && option.value !== optText) optLine += ` value="${option.value.replace(/"/g, "\\\"")}"`;
260
- lines.push(optLine);
215
+ function traverse(root, rootLevel, checkRefId) {
216
+ const pending = [{
217
+ element: root,
218
+ level: rootLevel
219
+ }];
220
+ while (pending.length) {
221
+ const { element, level } = pending.pop();
222
+ if (level > maxDepth || !element || !element.tagName) continue;
223
+ const include = shouldInclude(element, checkRefId) || checkRefId && level === 0;
224
+ if (include) {
225
+ const role = getRole(element);
226
+ const name = getName(element);
227
+ const elementRefId = getOrCreateRef(element);
228
+ let line = " ".repeat(level) + role;
229
+ if (name) line += ` "${name.replace(/\s+/g, " ").replace(/"/g, "\\\"")}"`;
230
+ line += ` [${elementRefId}]`;
231
+ const href = element.getAttribute("href");
232
+ if (href) line += ` href="${href}"`;
233
+ const type = element.getAttribute("type");
234
+ if (type) line += ` type="${type}"`;
235
+ const value = currentValue(element, name);
236
+ if (value !== void 0) line += ` value=${JSON.stringify(value)}`;
237
+ lines.push(line);
238
+ rememberInteractive(element, elementRefId, role, name, value);
239
+ if (element.tagName.toLowerCase() === "select") {
240
+ const select = element;
241
+ for (const option of select.options) {
242
+ let optLine = " ".repeat(level + 1) + "option";
243
+ const optText = option.textContent?.trim() || "";
244
+ if (optText) optLine += ` "${optText.replace(/\s+/g, " ").substring(0, 100).replace(/"/g, "\\\"")}"`;
245
+ if (option.selected) optLine += " (selected)";
246
+ if (option.value && option.value !== optText) optLine += ` value="${option.value.replace(/"/g, "\\\"")}"`;
247
+ lines.push(optLine);
248
+ }
261
249
  }
262
250
  }
251
+ if (element.children && level < maxDepth) {
252
+ const children = [...element.shadowRoot ? Array.from(element.shadowRoot.children) : [], ...Array.from(element.children)];
253
+ for (let index = children.length - 1; index >= 0; --index) pending.push({
254
+ element: children[index],
255
+ level: include ? level + 1 : level
256
+ });
257
+ }
263
258
  }
264
- if (element.children && level < maxDepth) for (const child of element.children) traverse(child, include ? level + 1 : level, checkRefId);
265
259
  }
266
260
  if (refId) {
267
261
  const ref = win.__mcpElementMap[refId];
@@ -310,7 +304,7 @@ function generateAccessibilityTree(filter, maxDepth, maxLength, refId, expectedU
310
304
  interactiveElements
311
305
  };
312
306
  }
313
- function performClick(refId) {
307
+ function performClick(refId, modifiers) {
314
308
  const ref = window.__mcpElementMap?.[refId];
315
309
  if (!ref) return {
316
310
  success: false,
@@ -327,7 +321,7 @@ function performClick(refId) {
327
321
  });
328
322
  const el = element;
329
323
  el.focus();
330
- el.click();
324
+ globalThis.__mcpDomHelpers.click(el, modifiers);
331
325
  return { success: true };
332
326
  }
333
327
  function performType(refId, text, clear) {
@@ -345,12 +339,18 @@ function performType(refId, text, clear) {
345
339
  el.focus();
346
340
  if ("value" in el) {
347
341
  el.value = clear ? text : el.value + text;
348
- el.dispatchEvent(new Event("input", { bubbles: true }));
342
+ el.dispatchEvent(new Event("input", {
343
+ bubbles: true,
344
+ composed: true
345
+ }));
349
346
  el.dispatchEvent(new Event("change", { bubbles: true }));
350
347
  } else if (element.contentEditable === "true") {
351
348
  if (clear) element.textContent = text;
352
349
  else element.textContent = (element.textContent || "") + text;
353
- element.dispatchEvent(new Event("input", { bubbles: true }));
350
+ element.dispatchEvent(new Event("input", {
351
+ bubbles: true,
352
+ composed: true
353
+ }));
354
354
  }
355
355
  return { success: true };
356
356
  }
@@ -385,48 +385,82 @@ function performScroll(x, y, refId) {
385
385
  };
386
386
  }
387
387
  async function executeCode(code, timeout) {
388
+ const errorText = (error) => {
389
+ try {
390
+ return error instanceof Error ? String(error.message) : String(error);
391
+ } catch {
392
+ return "Unprintable page exception";
393
+ }
394
+ };
388
395
  function evaluateSerializationError(message, suggestion, context) {
389
- return JSON.stringify({ error: {
390
- code: "NON_SERIALIZABLE_EVALUATE_RESULT",
391
- message,
392
- suggestion,
393
- context
394
- } });
396
+ return {
397
+ error: JSON.stringify({ error: {
398
+ code: "NON_SERIALIZABLE_EVALUATE_RESULT",
399
+ message,
400
+ suggestion,
401
+ context
402
+ } }),
403
+ errorMessage: message
404
+ };
395
405
  }
396
406
  function serializeEvaluateResult(result) {
397
- if (result instanceof Node) {
398
- const element = result instanceof Element ? result : result.parentElement;
399
- return {
407
+ try {
408
+ if (result instanceof Node) {
409
+ const element = result instanceof Element ? result : result.parentElement;
410
+ return {
411
+ success: false,
412
+ errorSource: "output",
413
+ ...evaluateSerializationError(`返回值是 DOM 节点 ${result.nodeName},不能直接 JSON 序列化`, "请返回 textContent、outerHTML、getAttribute(...) 等简单字段,或改用 extract type=\"text\"/\"html\"", {
414
+ nodeType: result.nodeType,
415
+ nodeName: result.nodeName,
416
+ selector: element?.id ? `#${CSS.escape(element.id)}` : element?.tagName.toLowerCase()
417
+ })
418
+ };
419
+ }
420
+ if (result instanceof NodeList || result instanceof HTMLCollection) return {
400
421
  success: false,
401
- error: evaluateSerializationError(`返回值是 DOM 节点 ${result.nodeName},不能直接 JSON 序列化`, "请返回 textContent、outerHTML、getAttribute(...) 等简单字段,或改用 extract type=\"text\"/\"html\"", {
402
- nodeType: result.nodeType,
403
- nodeName: result.nodeName,
404
- selector: element?.id ? `#${CSS.escape(element.id)}` : element?.tagName.toLowerCase()
422
+ errorSource: "output",
423
+ ...evaluateSerializationError(`返回值是 ${result.constructor.name},不能直接 JSON 序列化`, "请用 Array.from(value).map(...) 提取需要的字段,例如 textContent、href、outerHTML", {
424
+ className: result.constructor.name,
425
+ length: result.length
405
426
  })
406
427
  };
407
- }
408
- if (result instanceof NodeList || result instanceof HTMLCollection) return {
409
- success: false,
410
- error: evaluateSerializationError(`返回值是 ${result.constructor.name},不能直接 JSON 序列化`, "请用 Array.from(value).map(...) 提取需要的字段,例如 textContent、href、outerHTML", {
411
- className: result.constructor.name,
412
- length: result.length
413
- })
414
- };
415
- try {
416
428
  return {
417
429
  success: true,
418
430
  result: JSON.stringify(result)
419
431
  };
420
432
  } catch (error) {
421
- const errorMsg = error instanceof Error ? error.message : String(error);
422
- return {
423
- success: false,
424
- error: evaluateSerializationError(`evaluate 返回值无法 JSON 序列化: ${errorMsg}`, "请返回字符串、数字、布尔值、数组或普通对象,避免返回循环引用、BigInt、DOM 对象", { error: errorMsg })
425
- };
433
+ const errorMsg = errorText(error);
434
+ try {
435
+ return {
436
+ success: false,
437
+ errorSource: "output",
438
+ ...evaluateSerializationError(`evaluate 返回值检查或序列化失败: ${errorMsg}`, "请返回可 JSON 序列化的简单数据,并检查自定义原型或 getter 是否抛错", { error: errorMsg })
439
+ };
440
+ } catch (detailError) {
441
+ return {
442
+ success: false,
443
+ errorSource: "output",
444
+ errorCode: "NON_SERIALIZABLE_EVALUATE_RESULT",
445
+ error: `evaluate 返回值检查或序列化失败: ${errorMsg};输出错误详情生成失败: ${errorText(detailError)}`
446
+ };
447
+ }
426
448
  }
427
449
  }
450
+ let fn;
451
+ try {
452
+ fn = new Function(`return (${code})`);
453
+ } catch (error) {
454
+ return {
455
+ success: false,
456
+ error: errorText(error),
457
+ errorSource: "context",
458
+ actionExecuted: false,
459
+ ...error instanceof EvalError ? { errorCode: "CSP_BLOCKED" } : {}
460
+ };
461
+ }
428
462
  try {
429
- const result = new Function(`return (${code})`)();
463
+ const result = fn();
430
464
  if (timeout === void 0) return serializeEvaluateResult(await result);
431
465
  const timedOut = Symbol("evaluate-timeout");
432
466
  let timeoutId;
@@ -444,14 +478,10 @@ async function executeCode(code, timeout) {
444
478
  if (timeoutId !== void 0) clearTimeout(timeoutId);
445
479
  }
446
480
  } catch (error) {
447
- const errorMsg = error instanceof Error ? error.message : "Unknown error";
448
- if (errorMsg.includes("Content Security Policy") || errorMsg.includes("'unsafe-eval'")) return {
449
- success: false,
450
- error: `CSP 限制:此页面禁止动态代码执行,建议使用 extract 工具获取页面内容或使用 CDP 模式,原始错误: ${errorMsg}`
451
- };
452
481
  return {
453
482
  success: false,
454
- error: errorMsg
483
+ error: errorText(error),
484
+ errorSource: "page"
455
485
  };
456
486
  }
457
487
  }
@@ -601,87 +631,57 @@ function extractAttribute(selector, refId, attribute, expectedUrl) {
601
631
  }
602
632
  return { value: element.getAttribute(attribute) };
603
633
  }
604
- function findElements(selector, text, xpath, expectedUrl, point, matchIndex) {
634
+ function findElements(selector, text, xpath, expectedUrl, point, matchIndex, semantic) {
605
635
  if (expectedUrl != null && location.href !== expectedUrl) throw new Error("页面 URL 已变化,未读取");
636
+ const helpers = globalThis.__mcpDomHelpers;
637
+ if (!helpers) throw new Error("DOM query helpers are not installed");
638
+ if (!point && !selector && !text && !xpath && !semantic) return { error: "find requires at least one of: selector, xpath, text, semantic" };
606
639
  const win = window;
607
- win.__mcpElementMap = win.__mcpElementMap || {};
608
- win.__mcpElementToRefId = win.__mcpElementToRefId || /* @__PURE__ */ new WeakMap();
609
- win.__mcpRefCounter = win.__mcpRefCounter || 0;
610
- const results = [];
640
+ win.__mcpElementMap ??= {};
641
+ win.__mcpElementToRefId ??= /* @__PURE__ */ new WeakMap();
642
+ win.__mcpRefCounter ??= 0;
611
643
  let elements;
612
- if (point) {
613
- const element = document.elementFromPoint(point.x, point.y);
614
- elements = element ? [element] : [];
615
- } else if (xpath) {
616
- elements = [];
617
- const xpathResult = document.evaluate(xpath, document, null, XPathResult.ORDERED_NODE_SNAPSHOT_TYPE, null);
618
- for (let i = 0; i < xpathResult.snapshotLength; i++) {
619
- const node = xpathResult.snapshotItem(i);
620
- if (node instanceof Element) elements.push(node);
621
- }
622
- } else if (selector) try {
623
- elements = Array.from(document.querySelectorAll(selector));
624
- } catch (e) {
625
- const err = e;
626
- if (err?.name === "SyntaxError") return { error: `Invalid CSS selector: "${selector}" (${err.message})` };
627
- throw e;
644
+ try {
645
+ const hit = point ? helpers.deepElementFromPoint(point.x, point.y) : null;
646
+ elements = point ? hit ? [hit] : [] : helpers.query({
647
+ selector,
648
+ text,
649
+ xpath,
650
+ semantic
651
+ });
652
+ } catch (error) {
653
+ if (error.name === "SyntaxError") return { error: "Invalid CSS selector: " + selector };
654
+ throw error;
628
655
  }
629
- else if (text) {
630
- elements = [];
631
- const seen = /* @__PURE__ */ new Set();
632
- const walker = document.createTreeWalker(document.body || document.documentElement, NodeFilter.SHOW_TEXT, { acceptNode: (node) => node.data?.includes(text) ? NodeFilter.FILTER_ACCEPT : NodeFilter.FILTER_REJECT });
633
- let n = walker.nextNode();
634
- let textMatchIndex = 0;
635
- while (n && (matchIndex !== void 0 || elements.length < 200)) {
636
- const parent = n.parentElement;
637
- if (parent && !seen.has(parent)) {
638
- seen.add(parent);
639
- if (matchIndex === void 0 || textMatchIndex++ === matchIndex) {
640
- elements.push(parent);
641
- if (matchIndex !== void 0) break;
642
- }
643
- }
644
- n = walker.nextNode();
645
- }
646
- } else return { error: "find requires at least one of: selector, xpath, text" };
647
- let matched = 0;
648
- for (const element of elements) {
649
- if (text) {
650
- if (!(element.textContent || "").includes(text)) continue;
651
- }
652
- if (matchIndex !== void 0 && (selector || xpath || point) && matched++ !== matchIndex) continue;
653
- let refId = win.__mcpElementToRefId.get(element) ?? null;
654
- if (refId && win.__mcpElementMap[refId]?.deref() !== element) refId = null;
656
+ const results = (matchIndex == null ? elements.slice(0, 50) : elements.slice(matchIndex, matchIndex + 1)).map((element) => {
657
+ let refId = win.__mcpElementToRefId.get(element);
658
+ if (refId && win.__mcpElementMap[refId]?.deref() !== element) refId = void 0;
655
659
  if (!refId) {
656
- refId = `ref_${++win.__mcpRefCounter}`;
660
+ refId = "ref_" + ++win.__mcpRefCounter;
657
661
  win.__mcpElementMap[refId] = new WeakRef(element);
658
662
  win.__mcpElementToRefId.set(element, refId);
659
663
  }
660
664
  const rect = element.getBoundingClientRect();
661
- results.push({
665
+ return {
662
666
  refId,
663
667
  tag: element.tagName.toLowerCase(),
664
- text: (element.textContent || "").trim().substring(0, 100),
668
+ text: (element.textContent ?? "").trim().substring(0, 100),
665
669
  rect: {
666
670
  x: rect.x,
667
671
  y: rect.y,
668
672
  width: rect.width,
669
673
  height: rect.height
670
674
  }
671
- });
672
- if (matchIndex !== void 0 || results.length >= 50) break;
673
- }
674
- {
675
- const w = window;
676
- const counter = (w.__mcpSweepCounter ?? 0) + 1;
677
- w.__mcpSweepCounter = counter;
678
- if (counter % 10 === 0 || Object.keys(win.__mcpElementMap).length > 500) {
679
- for (const id of Object.keys(win.__mcpElementMap)) if (!win.__mcpElementMap[id].deref()) delete win.__mcpElementMap[id];
680
- }
675
+ };
676
+ });
677
+ const counter = (win.__mcpSweepCounter ?? 0) + 1;
678
+ win.__mcpSweepCounter = counter;
679
+ if (counter % 10 === 0 || Object.keys(win.__mcpElementMap).length > 500) {
680
+ for (const [key, ref] of Object.entries(win.__mcpElementMap)) if (!ref.deref()?.isConnected) delete win.__mcpElementMap[key];
681
681
  }
682
682
  return results;
683
683
  }
684
- function simulateMouseClick(x, y, button, clickCount = 1, refId) {
684
+ function simulateMouseClick(x, y, button, clickCount = 1, refId, modifiers) {
685
685
  let element = null;
686
686
  if (refId) {
687
687
  const resolved = (window.__mcpElementMap?.[refId])?.deref();
@@ -692,19 +692,21 @@ function simulateMouseClick(x, y, button, clickCount = 1, refId) {
692
692
  y = r.y + r.height / 2;
693
693
  }
694
694
  }
695
- if (!element) element = document.elementFromPoint(x, y);
695
+ if (!element) element = globalThis.__mcpDomHelpers.deepElementFromPoint(x, y);
696
696
  if (!element) return { success: false };
697
697
  const buttonCode = button === "right" ? 2 : button === "middle" ? 1 : 0;
698
698
  const buttonsMask = button === "right" ? 2 : button === "middle" ? 4 : 1;
699
699
  const baseOptions = {
700
700
  bubbles: true,
701
+ composed: true,
701
702
  cancelable: true,
702
703
  view: window,
703
704
  clientX: x,
704
705
  clientY: y,
705
706
  screenX: x + window.screenX,
706
707
  screenY: y + window.screenY,
707
- button: buttonCode
708
+ button: buttonCode,
709
+ ...modifiers
708
710
  };
709
711
  const pressed = {
710
712
  ...baseOptions,
@@ -717,7 +719,9 @@ function simulateMouseClick(x, y, button, clickCount = 1, refId) {
717
719
  element.dispatchEvent(new MouseEvent("mouseover", released));
718
720
  element.dispatchEvent(new MouseEvent("mouseenter", {
719
721
  ...released,
720
- bubbles: false
722
+ bubbles: false,
723
+ composed: false,
724
+ cancelable: false
721
725
  }));
722
726
  element.dispatchEvent(new MouseEvent("mousemove", released));
723
727
  const clickType = button === "right" ? "contextmenu" : button === "middle" ? "auxclick" : "click";
@@ -744,7 +748,7 @@ function simulateMouseClick(x, y, button, clickCount = 1, refId) {
744
748
  }
745
749
  async function simulateKeyboardType(text, delay, deadline) {
746
750
  const expired = () => deadline !== void 0 && Date.now() >= deadline;
747
- const activeElement = document.activeElement;
751
+ const activeElement = globalThis.__mcpDomHelpers.activeElement();
748
752
  if (!activeElement) return {
749
753
  success: false,
750
754
  error: "No active element"
@@ -775,6 +779,7 @@ async function simulateKeyboardType(text, delay, deadline) {
775
779
  };
776
780
  const keyEventOptions = {
777
781
  bubbles: true,
782
+ composed: true,
778
783
  cancelable: true,
779
784
  key: char,
780
785
  code: char >= "a" && char <= "z" ? `Key${char.toUpperCase()}` : char >= "A" && char <= "Z" ? `Key${char}` : char >= "0" && char <= "9" ? `Digit${char}` : "Key",
@@ -789,7 +794,7 @@ async function simulateKeyboardType(text, delay, deadline) {
789
794
  else if (activeElement.isContentEditable) activeElement.textContent = (activeElement.textContent || "") + char;
790
795
  activeElement.dispatchEvent(new InputEvent("input", {
791
796
  bubbles: true,
792
- cancelable: true,
797
+ composed: true,
793
798
  inputType: "insertText",
794
799
  data: char
795
800
  }));
@@ -805,9 +810,10 @@ async function simulateKeyboardType(text, delay, deadline) {
805
810
  }
806
811
  function simulateKeyEvent(key, type, modifiers, deadline) {
807
812
  if (deadline !== void 0 && Date.now() >= deadline) throw new Error("input timeout before event dispatch");
808
- const activeElement = document.activeElement || document.body;
813
+ const activeElement = globalThis.__mcpDomHelpers.activeElement() || document.body;
809
814
  const keyEventOptions = {
810
815
  bubbles: true,
816
+ composed: true,
811
817
  cancelable: true,
812
818
  key,
813
819
  code: key.length === 1 ? `Key${key.toUpperCase()}` : key,
@@ -822,13 +828,14 @@ function simulateKeyEvent(key, type, modifiers, deadline) {
822
828
  if (type === "up" || type === "press") activeElement.dispatchEvent(new KeyboardEvent("keyup", keyEventOptions));
823
829
  return { success: true };
824
830
  }
825
- function simulateMouseEvent(type, x, y, button, deadline) {
826
- if (deadline !== void 0 && Date.now() >= deadline) throw new Error("input timeout before mouse event dispatch");
827
- const element = document.elementFromPoint(x, y) || document.body;
831
+ function simulateMouseEvent(type, x, y, button, deadline, modifiers) {
832
+ if (deadline != null && Date.now() >= deadline) throw new Error("input timeout before mouse event dispatch");
833
+ const element = globalThis.__mcpDomHelpers.deepElementFromPoint(x, y) || document.body;
828
834
  const buttonCode = button === "right" ? 2 : button === "middle" ? 1 : 0;
829
835
  const buttonsMask = button === "right" ? 2 : button === "middle" ? 4 : 1;
830
836
  const eventOptions = {
831
837
  bubbles: true,
838
+ composed: type !== "mouseenter" && type !== "mouseleave",
832
839
  cancelable: true,
833
840
  view: window,
834
841
  clientX: x,
@@ -836,6 +843,7 @@ function simulateMouseEvent(type, x, y, button, deadline) {
836
843
  screenX: x + window.screenX,
837
844
  screenY: y + window.screenY,
838
845
  button: buttonCode,
846
+ ...modifiers,
839
847
  buttons: type === "mousedown" ? buttonsMask : 0
840
848
  };
841
849
  element.dispatchEvent(new MouseEvent(type, eventOptions));
@@ -1010,8 +1018,8 @@ function installActionabilityHelpers() {
1010
1018
  const vw = window.innerWidth;
1011
1019
  const vh = window.innerHeight;
1012
1020
  if (rect.bottom < 0 || rect.top > vh || rect.right < 0 || rect.left > vw) return failure("not-in-viewport");
1013
- const hitEl = document.elementFromPoint(clickPoint.x, clickPoint.y);
1014
- if (hitEl && hitEl !== element && !element.contains(hitEl) && !hitEl.contains(element)) return failure("covered", {
1021
+ const hitEl = globalThis.__mcpDomHelpers.deepElementFromPoint(clickPoint.x, clickPoint.y);
1022
+ if (hitEl && !globalThis.__mcpDomHelpers.containsComposed(element, hitEl)) return failure("covered", {
1015
1023
  coveringElement: describeElement(hitEl),
1016
1024
  coveringRect: plainRect(hitEl.getBoundingClientRect())
1017
1025
  });
@@ -1081,7 +1089,7 @@ function checkActionability(refId) {
1081
1089
  * 4. 验证 hit target
1082
1090
  * 5. 执行点击
1083
1091
  */
1084
- function performActionableClick(refId, force) {
1092
+ function performActionableClick(refId, force, modifiers) {
1085
1093
  const helpers = window.__mcpActionability;
1086
1094
  if (!helpers) return {
1087
1095
  success: false,
@@ -1091,13 +1099,17 @@ function performActionableClick(refId, force) {
1091
1099
  };
1092
1100
  function dispatchClickSequence(el) {
1093
1101
  const rect = el.getBoundingClientRect();
1102
+ const cx = Math.round(rect.x + rect.width / 2);
1103
+ const cy = Math.round(rect.y + rect.height / 2);
1094
1104
  const opts = {
1095
1105
  bubbles: true,
1106
+ composed: true,
1096
1107
  cancelable: true,
1097
1108
  button: 0,
1098
1109
  buttons: 1,
1099
- clientX: Math.round(rect.x + rect.width / 2),
1100
- clientY: Math.round(rect.y + rect.height / 2),
1110
+ ...modifiers,
1111
+ clientX: cx,
1112
+ clientY: cy,
1101
1113
  view: window
1102
1114
  };
1103
1115
  el.dispatchEvent(new MouseEvent("mousedown", opts));
@@ -1106,10 +1118,10 @@ function performActionableClick(refId, force) {
1106
1118
  ...opts,
1107
1119
  buttons: 0
1108
1120
  }));
1109
- el.dispatchEvent(new MouseEvent("click", {
1121
+ globalThis.__mcpDomHelpers.click(el, modifiers, {
1110
1122
  ...opts,
1111
1123
  buttons: 0
1112
- }));
1124
+ });
1113
1125
  }
1114
1126
  if (force) {
1115
1127
  const ref = window.__mcpElementMap?.[refId];
@@ -1208,12 +1220,32 @@ function dispatchInputToElement(refId, val) {
1208
1220
  success: false,
1209
1221
  error: `Element ${refId} not found`
1210
1222
  };
1223
+ const tag = el.namespaceURI === "http://www.w3.org/1999/xhtml" ? el.localName : void 0;
1224
+ const prototype = tag === "input" ? HTMLInputElement.prototype : tag === "textarea" ? HTMLTextAreaElement.prototype : tag === "select" ? HTMLSelectElement.prototype : void 0;
1225
+ if (!prototype && !el.isContentEditable) return {
1226
+ success: false,
1227
+ error: "controlled 输入需要 input、textarea、select 或 contenteditable 目标"
1228
+ };
1229
+ if (el.matches(":disabled") || "readOnly" in el && el.readOnly) return {
1230
+ success: false,
1231
+ error: "controlled 输入目标处于 disabled 或 readonly 状态"
1232
+ };
1233
+ if (tag === "input" && el.type === "file") return {
1234
+ success: false,
1235
+ error: "文件控件请使用 upload 事件"
1236
+ };
1237
+ const setter = prototype ? Object.getOwnPropertyDescriptor(prototype, "value")?.set : void 0;
1238
+ if (prototype && !setter) return {
1239
+ success: false,
1240
+ error: "controlled 输入目标的原生 value setter 不可用"
1241
+ };
1211
1242
  el.focus();
1212
- const proto = Object.getPrototypeOf(el);
1213
- const setter = Object.getOwnPropertyDescriptor(proto, "value") ?? Object.getOwnPropertyDescriptor(HTMLInputElement.prototype, "value") ?? Object.getOwnPropertyDescriptor(HTMLTextAreaElement.prototype, "value");
1214
- if (setter?.set) setter.set.call(el, val);
1215
- else el.value = val;
1216
- el.dispatchEvent(new Event("input", { bubbles: true }));
1243
+ if (setter) setter.call(el, val);
1244
+ else el.textContent = val;
1245
+ el.dispatchEvent(new Event("input", {
1246
+ bubbles: true,
1247
+ composed: true
1248
+ }));
1217
1249
  el.dispatchEvent(new Event("change", { bubbles: true }));
1218
1250
  return { success: true };
1219
1251
  }
@@ -1233,146 +1265,5 @@ function getComputedStyleFromElement(refId, prop, expectedUrl) {
1233
1265
  }
1234
1266
  return cs.getPropertyValue(prop);
1235
1267
  }
1236
- function inspectChallengePage(options) {
1237
- const title = document.title || "";
1238
- const url = location.href || "";
1239
- const visibleBodyText = (document.body && document.body.innerText ? document.body.innerText : "").replace(/\s+/g, " ");
1240
- const isVisible = (el) => {
1241
- if (!el) return false;
1242
- const style = window.getComputedStyle(el);
1243
- if (style.display === "none" || style.visibility === "hidden" || Number(style.opacity) === 0) return false;
1244
- const rect = el.getBoundingClientRect();
1245
- return rect.width > 0 && rect.height > 0;
1246
- };
1247
- const bringIntoView = (el) => {
1248
- if (!el || typeof el.scrollIntoView !== "function") return;
1249
- el.scrollIntoView({
1250
- block: "center",
1251
- inline: "nearest",
1252
- behavior: "instant"
1253
- });
1254
- };
1255
- const hits = (selectors) => selectors.filter((selector) => {
1256
- try {
1257
- return Array.from(document.querySelectorAll(selector)).some(isVisible);
1258
- } catch {
1259
- return false;
1260
- }
1261
- });
1262
- const isCloudflareFrame = (el) => {
1263
- if (!el) return false;
1264
- if (el.tagName.toUpperCase() === "IFRAME") {
1265
- const src = String(el.getAttribute("src") || el.src || "");
1266
- return src.includes("challenges.cloudflare.com") || src.includes("turnstile");
1267
- }
1268
- return Boolean(el.closest(options.frameSelectors.join(",")));
1269
- };
1270
- const selectorHits = hits(options.challengeSelectors);
1271
- const deniedHits = hits(options.deniedSelectors);
1272
- const widgetHits = hits(options.widgetSelectors);
1273
- const frameHits = hits(options.frameSelectors);
1274
- const cloudflareFramePresent = Array.from(document.querySelectorAll("iframe")).some((el) => isCloudflareFrame(el));
1275
- const normalizedTitle = title.trim().toLowerCase().replace(/…/g, "...");
1276
- const titlePending = options.titleNeedles.some((needle) => normalizedTitle.includes(String(needle).toLowerCase()));
1277
- const textHits = options.textMarkers.filter((marker) => visibleBodyText.toLowerCase().includes(String(marker).toLowerCase()));
1278
- const originResponsePending = options.originResponsePendingTextMarkers.some((marker) => visibleBodyText.toLowerCase().includes(String(marker).toLowerCase()));
1279
- const interstitialPending = selectorHits.length > 0 || titlePending || textHits.length > 0;
1280
- const findVisibleTurnstileBox = () => {
1281
- const input = document.querySelector("input[name=\"cf-turnstile-response\"]");
1282
- if (!input) return null;
1283
- const candidates = [];
1284
- let node = input.parentElement;
1285
- while (node && node !== document.documentElement) {
1286
- if (isVisible(node)) {
1287
- const rect = node.getBoundingClientRect();
1288
- if (rect.width >= 120 && rect.height >= 40) candidates.push(node);
1289
- }
1290
- node = node.parentElement;
1291
- }
1292
- if (candidates.length === 0) return null;
1293
- return candidates.find((el) => {
1294
- const rect = el.getBoundingClientRect();
1295
- return rect.width >= 250 && rect.width <= 340 && rect.height >= 50 && rect.height <= 85;
1296
- }) || candidates[0];
1297
- };
1298
- const hostVerify = Array.from(document.querySelectorAll(options.verifyButtonSelectors.join(","))).find(isVisible) || Array.from(document.querySelectorAll("button")).find((el) => {
1299
- const text = (el.textContent || "").trim();
1300
- return isVisible(el) && (text === "Verify you are human" || text === "请验证您是真人");
1301
- });
1302
- const turnstileBox = !originResponsePending && (interstitialPending || widgetHits.length > 0) ? findVisibleTurnstileBox() : null;
1303
- const turnstilePresent = widgetHits.length > 0 || Boolean(hostVerify) || !originResponsePending && interstitialPending && (cloudflareFramePresent || frameHits.length > 0 || Boolean(turnstileBox));
1304
- const useIframeClick = turnstilePresent && (cloudflareFramePresent || !hostVerify && interstitialPending && Boolean(document.querySelector("input[name=\"cf-turnstile-response\"]")));
1305
- const pointFromRect = (rect, kind) => {
1306
- if (!rect || rect.width < 8 || rect.height < 8) return null;
1307
- const y = Math.round(rect.top + Math.min(rect.height, 65) / 2);
1308
- if (kind === "verify") return {
1309
- x: Math.round(rect.left + rect.width / 2),
1310
- y
1311
- };
1312
- const widgetWidth = Math.min(rect.width, 300);
1313
- return {
1314
- x: Math.round(rect.left + Math.min(20, Math.max(14, widgetWidth / 15))),
1315
- y
1316
- };
1317
- };
1318
- let clickPoint = null;
1319
- let clickTargetKind = null;
1320
- let clickSource = null;
1321
- const setClickTarget = (el, kind) => {
1322
- if (!el) return;
1323
- bringIntoView(el);
1324
- const point = pointFromRect(el.getBoundingClientRect(), kind);
1325
- if (!point) return;
1326
- clickPoint = point;
1327
- clickTargetKind = kind;
1328
- clickSource = isCloudflareFrame(el) || useIframeClick ? "iframe" : "page";
1329
- };
1330
- if (hostVerify) setClickTarget(hostVerify, "verify");
1331
- if (!clickPoint && turnstileBox) {
1332
- const boxRect = turnstileBox.getBoundingClientRect();
1333
- if (boxRect.width <= 340 && boxRect.height <= 85) setClickTarget(turnstileBox, "widget");
1334
- }
1335
- if (!clickPoint && turnstilePresent) {
1336
- const frame = Array.from(document.querySelectorAll(options.frameSelectors.join(","))).find(isVisible);
1337
- if (frame) setClickTarget(frame, "widget");
1338
- }
1339
- if (!clickPoint && turnstilePresent) {
1340
- const widget = Array.from(document.querySelectorAll(options.widgetSelectors.join(","))).find(isVisible);
1341
- if (widget) setClickTarget(widget, "widget");
1342
- }
1343
- if (!clickPoint && turnstileBox) setClickTarget(turnstileBox, "widget");
1344
- const viewport = {
1345
- screenX: Number(window.screenX),
1346
- screenY: Number(window.screenY),
1347
- innerWidth: Number(window.innerWidth),
1348
- innerHeight: Number(window.innerHeight),
1349
- outerWidth: Number(window.outerWidth),
1350
- outerHeight: Number(window.outerHeight),
1351
- devicePixelRatio: Number(window.devicePixelRatio || 1)
1352
- };
1353
- const horizontal = Math.max(0, viewport.outerWidth - viewport.innerWidth);
1354
- const vertical = Math.max(0, viewport.outerHeight - viewport.innerHeight);
1355
- const chromeLeft = Math.round(horizontal / 2);
1356
- const chromeTop = Math.max(0, vertical - horizontal);
1357
- const resolvedClickPoint = clickPoint;
1358
- const screenPoint = resolvedClickPoint === null ? null : {
1359
- x: Math.round(viewport.screenX + chromeLeft + resolvedClickPoint.x),
1360
- y: Math.round(viewport.screenY + chromeTop + resolvedClickPoint.y)
1361
- };
1362
- return {
1363
- title,
1364
- url,
1365
- selectorHits,
1366
- deniedHits,
1367
- textHits,
1368
- originResponsePending,
1369
- turnstilePresent,
1370
- clickPoint: resolvedClickPoint,
1371
- clickTargetKind,
1372
- clickSource,
1373
- screenPoint,
1374
- viewport
1375
- };
1376
- }
1377
1268
  //#endregion
1378
- export { simulateMouseClick as C, simulateKeyboardType as S, performClick as _, extractHtml as a, performType as b, extractText as c, getComputedStyleFromElement as d, injectStealthScripts as f, performActionableClick as g, installFrameProbeListener as h, extractAttribute as i, findElements as l, installActionabilityHelpers as m, dispatchInputToElement as n, extractHtmlWithImages as o, inspectChallengePage as p, executeCode as r, extractMetadata as s, checkActionability as t, generateAccessibilityTree as u, performDragAndDrop as v, simulateMouseEvent as w, simulateKeyEvent as x, performScroll as y };
1269
+ export { simulateMouseClick as C, simulateKeyboardType as S, performClick as _, extractHtml as a, performType as b, extractText as c, getComputedStyleFromElement as d, injectStealthScripts as f, performActionableClick as g, observeNativePointer as h, extractAttribute as i, findElements as l, installFrameProbeListener as m, dispatchInputToElement as n, extractHtmlWithImages as o, installActionabilityHelpers as p, executeCode as r, extractMetadata as s, checkActionability as t, generateAccessibilityTree as u, performDragAndDrop as v, simulateMouseEvent as w, simulateKeyEvent as x, performScroll as y };