add remove all unique ids (#3964)
This commit is contained in:
@@ -2725,6 +2725,34 @@ function isAnimationFinished() {
|
|||||||
return false;
|
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:
|
// How to run the code:
|
||||||
|
|||||||
@@ -486,6 +486,10 @@ class SkyvernFrame:
|
|||||||
js_script = "([element]) => getElementDomDepth(element)"
|
js_script = "([element]) => getElementDomDepth(element)"
|
||||||
return await self.evaluate(frame=self.frame, expression=js_script, arg=[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()
|
@TraceManager.traced_async()
|
||||||
async def build_tree_from_body(
|
async def build_tree_from_body(
|
||||||
self,
|
self,
|
||||||
|
|||||||
Reference in New Issue
Block a user