Skip to content

Commit

Permalink
Move a tag href target rewriting to the core loop to prevent new tabs…
Browse files Browse the repository at this point in the history
… from being opened (#475)
  • Loading branch information
ykeremy committed Jun 16, 2024
1 parent c578e1a commit 536736a
Showing 1 changed file with 9 additions and 7 deletions.
16 changes: 9 additions & 7 deletions skyvern/webeye/scraper/domUtils.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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);
Expand Down

0 comments on commit 536736a

Please sign in to comment.