@quanta-intellect/vessel-browser 0.1.35 → 0.1.44

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.
@@ -3187,9 +3187,25 @@ function vesselExtractContent() {
3187
3187
  function resolveElementSelector(index) {
3188
3188
  return elementSelectors[index] || null;
3189
3189
  }
3190
+ function resolveElementIndexBySelector(selector) {
3191
+ if (!selector || typeof selector !== "string") return null;
3192
+ let el = null;
3193
+ try {
3194
+ if (selector.includes(" >>> ")) {
3195
+ el = resolveShadowSelector(selector);
3196
+ } else {
3197
+ el = document.querySelector(selector);
3198
+ }
3199
+ } catch {
3200
+ return null;
3201
+ }
3202
+ if (!el) return null;
3203
+ const existing = indexedElements.get(el);
3204
+ return typeof existing === "number" ? existing : null;
3205
+ }
3190
3206
  function interactByIndex(index, action, value) {
3191
3207
  const el = indexedElementRefs[index];
3192
- if (!el || !(el instanceof HTMLElement)) {
3208
+ if (!el || !(el instanceof HTMLElement) || !document.contains(el)) {
3193
3209
  return "Error[stale-index]: Element not found — the page may have changed. Call read_page to refresh.";
3194
3210
  }
3195
3211
  if (action === "click") {
@@ -3214,7 +3230,9 @@ function interactByIndex(index, action, value) {
3214
3230
  }
3215
3231
  return `${ariaChecked === "true" ? "Selected" : "Clicked"}: ${label}`;
3216
3232
  }
3217
- return "Clicked: " + (el.getAttribute("aria-label") || el.textContent?.trim().slice(0, 60) || el.tagName.toLowerCase());
3233
+ const anchor = el instanceof HTMLAnchorElement ? el : el.closest("a[href]");
3234
+ const href = anchor instanceof HTMLAnchorElement ? anchor.href : null;
3235
+ return "Clicked: " + (el.getAttribute("aria-label") || el.textContent?.trim().slice(0, 60) || el.tagName.toLowerCase()) + (href ? "\nhref: " + href : "");
3218
3236
  }
3219
3237
  if (action === "focus") {
3220
3238
  el.focus();
@@ -3241,6 +3259,7 @@ function interactByIndex(index, action, value) {
3241
3259
  electron.contextBridge.exposeInMainWorld("__vessel", {
3242
3260
  extractContent: vesselExtractContent,
3243
3261
  getElementSelector: resolveElementSelector,
3262
+ getElementIndexBySelector: resolveElementIndexBySelector,
3244
3263
  interactByIndex,
3245
3264
  resolveShadowSelector,
3246
3265
  notifyHighlightSelection: (text) => {