@coolkiller007/my-page-agent 0.1.4 → 0.1.5

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/index.js CHANGED
@@ -125,7 +125,7 @@ async function clickElement(element) {
125
125
  const y = rect.top + rect.height / 2;
126
126
  await movePointerToElement(element, x, y);
127
127
  await clickPointer();
128
- await waitFor$1(.1);
128
+ await waitFor$1(.05);
129
129
  const doc = element.ownerDocument;
130
130
  await enablePassThrough();
131
131
  const hitTarget = doc.elementFromPoint(x, y);
@@ -161,7 +161,7 @@ async function clickElement(element) {
161
161
  target.dispatchEvent(new PointerEvent("pointerup", pointerOpts));
162
162
  target.dispatchEvent(new MouseEvent("mouseup", mouseOpts));
163
163
  target.click();
164
- await waitFor$1(.2);
164
+ await waitFor$1(.1);
165
165
  }
166
166
  /**
167
167
  * @private Internal method, subject to change at any time.
@@ -210,7 +210,7 @@ async function inputTextElement(element, text) {
210
210
  element.blur();
211
211
  } else getNativeValueSetter(element).call(element, text);
212
212
  if (!isContentEditable) element.dispatchEvent(new Event("input", { bubbles: true }));
213
- await waitFor$1(.1);
213
+ await waitFor$1(.05);
214
214
  blurLastClickedElement();
215
215
  }
216
216
  /**
@@ -223,7 +223,7 @@ async function selectOptionElement(selectElement, optionText) {
223
223
  if (!option) throw new Error(`Option with text "${optionText}" not found in select element`);
224
224
  selectElement.value = option.value;
225
225
  selectElement.dispatchEvent(new Event("change", { bubbles: true }));
226
- await waitFor$1(.1);
226
+ await waitFor$1(.05);
227
227
  }
228
228
  /**
229
229
  * @private Internal method, subject to change at any time.
@@ -1325,6 +1325,27 @@ var dom_tree_default = (args = {
1325
1325
  * @edit @workaround input.checked
1326
1326
  */
1327
1327
  if (node.tagName.toLowerCase() === "input" && (node.type === "checkbox" || node.type === "radio")) nodeData.attributes.checked = node.checked ? "true" : "false";
1328
+ /**
1329
+ * @edit @workaround select.value
1330
+ * select 的选中状态是 DOM 属性(selectedIndex/value),不会反映到 HTML attribute 上,
1331
+ * 若不同步,选择后重新快照时 LLM 看不到变化,会误判操作未生效而反复执行 select 操作。
1332
+ */
1333
+ if (node.tagName.toLowerCase() === "select") {
1334
+ const selectedOption = node.options[node.selectedIndex];
1335
+ nodeData.attributes.value = selectedOption ? selectedOption.text : node.value;
1336
+ }
1337
+ /**
1338
+ * @edit @workaround label-wrapped checkbox/radio checked
1339
+ * 常见组件库(如 antd)把 checkbox/radio 包在 <label> 里,视觉上的选中框覆盖在原生
1340
+ * input 上面,导致 input 不是 isTopElement,不会被收进可交互树、也就打印不出 checked
1341
+ * 状态。真正可点击并带 highlightIndex 的是这个 <label>,所以把关联 input 的 checked
1342
+ * 状态同步到 label 自己的 attributes 上,否则 LLM 看不到勾选反馈会反复点击。
1343
+ */
1344
+ if (node.tagName.toLowerCase() === "label") {
1345
+ const forId = node.getAttribute("for");
1346
+ const input = node.querySelector("input[type=\"checkbox\"], input[type=\"radio\"]") || forId && document.getElementById(forId);
1347
+ if (input && (input.type === "checkbox" || input.type === "radio")) nodeData.attributes.checked = input.checked ? "true" : "false";
1348
+ }
1328
1349
  }
1329
1350
  let nodeWasHighlighted = false;
1330
1351
  if (node.nodeType === Node.ELEMENT_NODE) {
@@ -4107,7 +4128,7 @@ var AgentRuntime = class extends EventTarget {
4107
4128
  const onAfterStep = this.config.onAfterStep;
4108
4129
  const onBeforeTask = this.config.onBeforeTask;
4109
4130
  const onAfterTask = this.config.onAfterTask;
4110
- const stepDelay = this.config.stepDelay ?? .4;
4131
+ const stepDelay = this.config.stepDelay ?? .2;
4111
4132
  const maxSteps = this.config.maxSteps;
4112
4133
  let step = 0;
4113
4134
  let taskResult;