fix new tab a issue (#2437)

This commit is contained in:
Shuchang Zheng
2025-05-22 22:18:42 -07:00
committed by GitHub
parent f49b5c4100
commit cca2772765
4 changed files with 70 additions and 14 deletions

View File

@@ -1378,6 +1378,15 @@ async function buildElementObject(
isSelect2MultiChoice(element),
};
// if element is an "a" tag and has a target="_blank" attribute, remove the target attribute but keep it in the elementObj
// We're doing this so that skyvern can do all the navigation in a single page/tab and not open new tab
if (elementTagNameLower === "a") {
if (element.getAttribute("target") === "_blank") {
elementObj.target = "_blank";
element.removeAttribute("target");
}
}
let isInShadowRoot = element.getRootNode() instanceof ShadowRoot;
if (isInShadowRoot) {
let shadowHostEle = element.getRootNode().host;
@@ -1472,14 +1481,6 @@ async function buildElementTree(
"]";
}
// 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 (tagName === "a") {
if (element.getAttribute("target") === "_blank") {
element.removeAttribute("target");
}
}
let shadowDOMchildren = [];
// sometimes the shadowRoot is not visible, but the elemnets in the shadowRoot are visible
if (element.shadowRoot) {

View File

@@ -869,6 +869,9 @@ def trim_element(element: dict) -> dict:
if "afterPseudoText" in queue_ele and not queue_ele.get("afterPseudoText"):
del queue_ele["afterPseudoText"]
if "target" in queue_ele:
del queue_ele["target"]
return element