auto-webmcp 0.3.12 → 0.3.13

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.
@@ -1331,6 +1331,14 @@ function fillAriaField(el, value) {
1331
1331
  return;
1332
1332
  }
1333
1333
  const htmlEl = el;
1334
+ console.log("[auto-webmcp] fillAriaField", {
1335
+ tag: el.tagName,
1336
+ role,
1337
+ isContentEditable: htmlEl.isContentEditable,
1338
+ id: el.id,
1339
+ ariaLabel: el.getAttribute("aria-label"),
1340
+ textContentBefore: (htmlEl.textContent ?? "").slice(0, 80)
1341
+ });
1334
1342
  if (htmlEl.isContentEditable) {
1335
1343
  htmlEl.focus();
1336
1344
  const range = document.createRange();
@@ -1338,23 +1346,61 @@ function fillAriaField(el, value) {
1338
1346
  const sel = window.getSelection();
1339
1347
  sel?.removeAllRanges();
1340
1348
  sel?.addRange(range);
1341
- let handled = false;
1349
+ const text = String(value ?? "");
1350
+ console.log("[auto-webmcp] fillAriaField: text to insert:", JSON.stringify(text));
1351
+ let inserted = false;
1342
1352
  try {
1343
1353
  const dt = new DataTransfer();
1344
- dt.setData("text/plain", String(value ?? ""));
1345
- const ev = new ClipboardEvent("paste", {
1354
+ dt.setData("text/plain", text);
1355
+ htmlEl.dispatchEvent(new ClipboardEvent("paste", {
1346
1356
  bubbles: true,
1347
1357
  cancelable: true,
1348
1358
  composed: true,
1349
1359
  clipboardData: dt
1350
- });
1351
- handled = !htmlEl.dispatchEvent(ev);
1352
- } catch {
1360
+ }));
1361
+ inserted = (htmlEl.textContent ?? "").trim().length > 0;
1362
+ console.log("[auto-webmcp] fillAriaField: S1 paste result:", inserted, JSON.stringify((htmlEl.textContent ?? "").slice(0, 80)));
1363
+ } catch (e) {
1364
+ console.log("[auto-webmcp] fillAriaField: S1 paste threw:", e);
1365
+ }
1366
+ if (!inserted) {
1367
+ const ok = document.execCommand("insertText", false, text);
1368
+ inserted = (htmlEl.textContent ?? "").trim().length > 0;
1369
+ console.log("[auto-webmcp] fillAriaField: S2 execCommand result:", ok, "inserted:", inserted, JSON.stringify((htmlEl.textContent ?? "").slice(0, 80)));
1370
+ }
1371
+ if (!inserted) {
1372
+ try {
1373
+ htmlEl.dispatchEvent(new InputEvent("beforeinput", {
1374
+ bubbles: true,
1375
+ cancelable: true,
1376
+ composed: true,
1377
+ inputType: "insertText",
1378
+ data: text
1379
+ }));
1380
+ inserted = (htmlEl.textContent ?? "").trim().length > 0;
1381
+ console.log("[auto-webmcp] fillAriaField: S3 beforeinput result:", inserted, JSON.stringify((htmlEl.textContent ?? "").slice(0, 80)));
1382
+ } catch (e) {
1383
+ console.log("[auto-webmcp] fillAriaField: S3 beforeinput threw:", e);
1384
+ }
1353
1385
  }
1354
- if (!handled) {
1355
- document.execCommand("insertText", false, String(value ?? ""));
1386
+ if (!inserted) {
1387
+ htmlEl.textContent = text;
1388
+ const r2 = document.createRange();
1389
+ r2.selectNodeContents(htmlEl);
1390
+ r2.collapse(false);
1391
+ sel?.removeAllRanges();
1392
+ sel?.addRange(r2);
1393
+ console.log("[auto-webmcp] fillAriaField: S4 textContent assignment done, textContent:", JSON.stringify((htmlEl.textContent ?? "").slice(0, 80)));
1356
1394
  }
1395
+ htmlEl.dispatchEvent(new InputEvent("input", {
1396
+ bubbles: true,
1397
+ cancelable: true,
1398
+ inputType: "insertText",
1399
+ data: text
1400
+ }));
1401
+ console.log("[auto-webmcp] fillAriaField: done, final textContent:", JSON.stringify((htmlEl.textContent ?? "").slice(0, 80)));
1357
1402
  } else {
1403
+ console.log("[auto-webmcp] fillAriaField: not contentEditable, dispatching input/change only");
1358
1404
  el.dispatchEvent(new Event("input", { bubbles: true }));
1359
1405
  el.dispatchEvent(new Event("change", { bubbles: true }));
1360
1406
  }
@@ -1700,6 +1746,31 @@ async function scanOrphanInputs(config) {
1700
1746
  if (submitBtn)
1701
1747
  console.log(`[auto-webmcp] orphan: using text-matched button in container: "${submitBtn.textContent?.trim()}"`);
1702
1748
  }
1749
+ if (!submitBtn) {
1750
+ const dialog = container.closest('[role="dialog"], [aria-modal="true"]');
1751
+ if (dialog) {
1752
+ const allDialogBtns = Array.from(
1753
+ dialog.querySelectorAll('button, [role="button"]')
1754
+ ).filter((b) => {
1755
+ const r = b.getBoundingClientRect();
1756
+ return r.width > 0 && r.height > 0 && SUBMIT_TEXT_RE.test(b.textContent ?? "");
1757
+ });
1758
+ console.log(
1759
+ `[auto-webmcp] orphan: dialog buttons matching submit text:`,
1760
+ allDialogBtns.map((b) => `"${b.textContent?.trim().slice(0, 30)}" disabled=${b.disabled} aria-disabled=${b.getAttribute("aria-disabled")}`)
1761
+ );
1762
+ const disabledBtns = allDialogBtns.filter(
1763
+ (b) => b.disabled || b.getAttribute("aria-disabled") === "true"
1764
+ );
1765
+ const enabledBtns = allDialogBtns.filter(
1766
+ (b) => !b.disabled && b.getAttribute("aria-disabled") !== "true"
1767
+ );
1768
+ const dialogBtns = disabledBtns.length > 0 ? disabledBtns : enabledBtns;
1769
+ submitBtn = dialogBtns[dialogBtns.length - 1] ?? null;
1770
+ if (submitBtn)
1771
+ console.log(`[auto-webmcp] orphan: using text-matched button in dialog: "${submitBtn.textContent?.trim().slice(0, 40)}" disabled=${submitBtn.disabled} aria-disabled=${submitBtn.getAttribute("aria-disabled")}`);
1772
+ }
1773
+ }
1703
1774
  if (!submitBtn) {
1704
1775
  const pageBtns = Array.from(
1705
1776
  document.querySelectorAll('button, [role="button"]')