From 536736a7bf4e5f80680ab516f7ac505dac352b5c Mon Sep 17 00:00:00 2001 From: Kerem Yilmaz Date: Sat, 15 Jun 2024 20:56:23 -0700 Subject: [PATCH] Move a tag href target rewriting to the core loop to prevent new tabs from being opened (#475) --- skyvern/webeye/scraper/domUtils.js | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) diff --git a/skyvern/webeye/scraper/domUtils.js b/skyvern/webeye/scraper/domUtils.js index 2fdf7631..1dc227af 100644 --- a/skyvern/webeye/scraper/domUtils.js +++ b/skyvern/webeye/scraper/domUtils.js @@ -665,13 +665,7 @@ function buildTreeFromBody(frame = "main.frame") { var element_id = element.getAttribute("unique_id") ?? uniqueId(); var elementTagNameLower = element.tagName.toLowerCase(); element.setAttribute("unique_id", element_id); - // if element is an "a" tag and has a target="_blank" attribute, remove the target attribute - // We're doing this so that skyvern can do all the navigation in a single page/tab and not open new tab - if (element.tagName.toLowerCase() === "a") { - if (element.getAttribute("target") === "_blank") { - element.removeAttribute("target"); - } - } + const attrs = {}; for (const attr of element.attributes) { var attrValue = attr.value; @@ -762,6 +756,14 @@ function buildTreeFromBody(frame = "main.frame") { return; } + // if element is an "a" tag and has a target="_blank" attribute, remove the target attribute + // We're doing this so that skyvern can do all the navigation in a single page/tab and not open new tab + if (element.tagName.toLowerCase() === "a") { + if (element.getAttribute("target") === "_blank") { + element.removeAttribute("target"); + } + } + // Check if the element is interactable if (isInteractable(element)) { var elementObj = buildElementObject(element, true);