diff --git a/src/components/browser/BrowserWindow.tsx b/src/components/browser/BrowserWindow.tsx index 997f47a3..51055e9a 100644 --- a/src/components/browser/BrowserWindow.tsx +++ b/src/components/browser/BrowserWindow.tsx @@ -483,31 +483,31 @@ export const BrowserWindow = () => { validatedChildSelectors.forEach((selector, index) => { try { const listElements = evaluateXPathAllWithShadowSupport( - iframeElement.contentDocument!, - listSelector, - listSelector.includes(">>") || listSelector.startsWith("//") - ); - - if (listElements.length === 0) return; - - const hasNumericPredicate = /\[\d+\](?![^\[]*@)/.test(selector); - - if (hasNumericPredicate && listElements.length >= 3) { - const allMatches = evaluateXPathAllWithShadowSupport( iframeElement.contentDocument!, - selector, - selector.includes(">>") || selector.startsWith("//") + listSelector, + listSelector.includes(">>") || listSelector.startsWith("//") ); - const matchRatio = allMatches.length / listElements.length; + if (listElements.length === 0) return; - if (matchRatio < 0.6) { - return; + const hasNumericPredicate = /\[\d+\](?![^\[]*@)/.test(selector); + + if (hasNumericPredicate && listElements.length >= 3) { + const allMatches = evaluateXPathAllWithShadowSupport( + iframeElement.contentDocument!, + selector, + selector.includes(">>") || selector.startsWith("//") + ); + + const matchRatio = allMatches.length / listElements.length; + + if (matchRatio < 0.6) { + return; + } } - } - const firstListElement = listElements[0]; - + const firstListElement = listElements[0]; + const elements = evaluateXPathAllWithShadowSupport( iframeElement.contentDocument!, selector, @@ -629,32 +629,32 @@ export const BrowserWindow = () => { } } - const fieldId = Date.now() + index * 1000 + 500; - candidateFields.push({ - id: fieldId, - element: anchorParent as HTMLElement, - isLeaf: true, - depth: 0, - position: position, - field: { - id: fieldId, - type: "text", - label: `Label ${index + 1} Link`, - data: href, - selectorObj: { - selector: anchorSelector, - attribute: 'href', - tag: 'A', - isShadow: anchorParent.getRootNode() instanceof ShadowRoot, - fallbackSelector: generateFallbackSelector(anchorParent as HTMLElement) - } + const fieldId = Date.now() + index * 1000 + 500; + candidateFields.push({ + id: fieldId, + element: anchorParent as HTMLElement, + isLeaf: true, + depth: 0, + position: position, + field: { + id: fieldId, + type: "text", + label: `Label ${index + 1} Link`, + data: href, + selectorObj: { + selector: anchorSelector, + attribute: 'href', + tag: 'A', + isShadow: anchorParent.getRootNode() instanceof ShadowRoot, + } + } + }); } - }); + } } } } - } - } catch (error) { + } catch (error) { console.warn(`Failed to process child selector ${selector}:`, error); } });