Move a tag href target rewriting to the core loop to prevent new tabs from being opened (#475)

This commit is contained in:
Kerem Yilmaz
2024-06-15 20:56:23 -07:00
committed by GitHub
parent c578e1a21d
commit 536736a7bf

View File

@@ -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);