auto-webmcp 0.3.20 → 0.3.21

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.
@@ -1900,16 +1900,48 @@ function getMissingRequired(metadata, params) {
1900
1900
  return [];
1901
1901
  return metadata.inputSchema.required.filter((fieldKey) => !(fieldKey in params));
1902
1902
  }
1903
+ function queryShadowAll(root, selector) {
1904
+ const results = [];
1905
+ const hosts = Array.from(root.querySelectorAll?.("*") ?? []);
1906
+ for (const host of hosts) {
1907
+ const sr = host.shadowRoot;
1908
+ if (!sr)
1909
+ continue;
1910
+ results.push(...Array.from(sr.querySelectorAll(selector)));
1911
+ results.push(...queryShadowAll(sr, selector));
1912
+ }
1913
+ return results;
1914
+ }
1903
1915
  async function fillComboboxButton(el, value) {
1904
1916
  const text = String(value ?? "").trim();
1905
1917
  console.log("[auto-webmcp] fillComboboxButton: clicking button, value=", JSON.stringify(text));
1918
+ el.dispatchEvent(new PointerEvent("pointerdown", { bubbles: true, cancelable: true }));
1919
+ el.dispatchEvent(new MouseEvent("mousedown", { bubbles: true, cancelable: true }));
1906
1920
  el.dispatchEvent(new MouseEvent("click", { bubbles: true, cancelable: true }));
1921
+ const ariaControlsId = el.getAttribute("aria-controls");
1907
1922
  const listbox = await new Promise((resolve) => {
1908
1923
  const deadline = Date.now() + 3e3;
1909
1924
  const poll = () => {
1910
- const candidate = document.querySelector('[role="listbox"]') ?? document.querySelector('[role="option"]')?.closest('[role="listbox"]') ?? null;
1911
- if (candidate) {
1912
- resolve(candidate);
1925
+ if (ariaControlsId) {
1926
+ const byId = document.getElementById(ariaControlsId);
1927
+ if (byId) {
1928
+ resolve(byId);
1929
+ return;
1930
+ }
1931
+ const inShadow = queryShadowAll(document.body, `#${CSS.escape(ariaControlsId)}`)[0] ?? null;
1932
+ if (inShadow) {
1933
+ resolve(inShadow);
1934
+ return;
1935
+ }
1936
+ }
1937
+ const lightCandidate = document.querySelector('[role="listbox"]') ?? document.querySelector('[role="option"]')?.closest('[role="listbox"]') ?? null;
1938
+ if (lightCandidate) {
1939
+ resolve(lightCandidate);
1940
+ return;
1941
+ }
1942
+ const shadowCandidate = queryShadowAll(document.body, '[role="listbox"]')[0] ?? null;
1943
+ if (shadowCandidate) {
1944
+ resolve(shadowCandidate);
1913
1945
  return;
1914
1946
  }
1915
1947
  if (Date.now() >= deadline) {
@@ -1921,11 +1953,13 @@ async function fillComboboxButton(el, value) {
1921
1953
  poll();
1922
1954
  });
1923
1955
  if (!listbox) {
1924
- console.warn("[auto-webmcp] fillComboboxButton: listbox did not appear after 1s");
1956
+ console.warn("[auto-webmcp] fillComboboxButton: listbox did not appear after 3s");
1925
1957
  return;
1926
1958
  }
1927
- const options = Array.from(listbox.querySelectorAll('[role="option"]'));
1928
- console.log("[auto-webmcp] fillComboboxButton: listbox has", options.length, "options");
1959
+ const lightOptions = Array.from(listbox.querySelectorAll('[role="option"]'));
1960
+ const shadowOptions = queryShadowAll(listbox, '[role="option"]');
1961
+ const options = lightOptions.length > 0 ? lightOptions : shadowOptions;
1962
+ console.log("[auto-webmcp] fillComboboxButton: listbox has", options.length, "option(s)");
1929
1963
  const lowerValue = text.toLowerCase();
1930
1964
  const match = options.find((opt) => {
1931
1965
  const dataValue = (opt.getAttribute("data-value") ?? "").toLowerCase();
@@ -1934,14 +1968,16 @@ async function fillComboboxButton(el, value) {
1934
1968
  return dataValue === lowerValue || ariaLabel === lowerValue || optText === lowerValue;
1935
1969
  });
1936
1970
  if (match) {
1937
- console.log("[auto-webmcp] fillComboboxButton: clicking option", match.textContent?.trim());
1971
+ console.log("[auto-webmcp] fillComboboxButton: selecting option", match.textContent?.trim());
1972
+ match.dispatchEvent(new PointerEvent("pointerdown", { bubbles: true, cancelable: true }));
1973
+ match.dispatchEvent(new MouseEvent("mousedown", { bubbles: true, cancelable: true }));
1938
1974
  match.dispatchEvent(new MouseEvent("click", { bubbles: true, cancelable: true }));
1939
1975
  } else {
1940
1976
  console.warn(
1941
1977
  "[auto-webmcp] fillComboboxButton: no option matched",
1942
1978
  JSON.stringify(text),
1943
1979
  "available:",
1944
- options.map((o) => o.textContent?.trim())
1980
+ options.map((o) => o.getAttribute("data-value") ?? o.textContent?.trim())
1945
1981
  );
1946
1982
  }
1947
1983
  }