add remove all unique ids (#3964)

This commit is contained in:
LawyZheng
2025-11-12 02:41:55 +08:00
committed by GitHub
parent 887a8a9b64
commit 4cf6757d05
2 changed files with 32 additions and 0 deletions

View File

@@ -2725,6 +2725,34 @@ function isAnimationFinished() {
return false;
}
/**
* Remove unique_id attribute from all elements on the page.
* This includes elements in the main document and shadow DOM.
*/
function removeAllUniqueIds() {
// Function to recursively remove unique_id from an element and its children
const removeUniqueIdFromElement = (element) => {
if (element.hasAttribute("unique_id")) {
element.removeAttribute("unique_id");
}
// Process children in the main DOM
for (const child of Array.from(element.children)) {
removeUniqueIdFromElement(child);
}
// Process elements in shadow DOM if present
if (element.shadowRoot) {
for (const shadowChild of Array.from(element.shadowRoot.children)) {
removeUniqueIdFromElement(shadowChild);
}
}
};
// Start from document.documentElement to process the entire page
removeUniqueIdFromElement(document.documentElement);
}
/**
// How to run the code:

View File

@@ -486,6 +486,10 @@ class SkyvernFrame:
js_script = "([element]) => getElementDomDepth(element)"
return await self.evaluate(frame=self.frame, expression=js_script, arg=[element])
async def remove_all_unique_ids(self) -> None:
js_script = "() => removeAllUniqueIds()"
await self.evaluate(frame=self.frame, expression=js_script)
@TraceManager.traced_async()
async def build_tree_from_body(
self,