fix search on auto completion (#1544)

This commit is contained in:
LawyZheng
2025-01-14 13:08:35 +08:00
committed by GitHub
parent a798757541
commit d63061f13b
5 changed files with 51 additions and 11 deletions

View File

@@ -2132,15 +2132,26 @@ if (window.globalObserverForDOMIncrement === undefined) {
}
if (mutation.type === "childList") {
if (mutation.target.nodeType === Node.TEXT_NODE) continue;
const node = mutation.target;
let changedNode = {
targetNode: mutation.target, // TODO: for future usage, when we want to parse new elements into a tree
targetNode: node, // TODO: for future usage, when we want to parse new elements into a tree
};
let newNodes = [];
if (mutation.addedNodes && mutation.addedNodes.length > 0) {
for (const node of mutation.addedNodes) {
// skip the text nodes, they won't be interactable
if (node.nodeType === Node.TEXT_NODE) continue;
newNodes.push(node);
if (
node.tagName.toLowerCase() === "ul" ||
(node.tagName.toLowerCase() === "div" &&
node.hasAttribute("role") &&
node.getAttribute("role").toLowerCase() === "listbox")
) {
newNodes.push(node);
} else {
if (mutation.addedNodes && mutation.addedNodes.length > 0) {
for (const node of mutation.addedNodes) {
// skip the text nodes, they won't be interactable
if (node.nodeType === Node.TEXT_NODE) continue;
newNodes.push(node);
}
}
}
if (newNodes.length > 0) {

View File

@@ -575,6 +575,10 @@ class IncrementalScrapePage:
await SkyvernFrame.evaluate(frame=self.skyvern_frame.get_frame(), expression=js_script)
async def stop_listen_dom_increment(self) -> None:
# check if the DOM has navigated away or refreshed
js_script = "() => window.globalObserverForDOMIncrement === undefined"
if await SkyvernFrame.evaluate(frame=self.skyvern_frame.get_frame(), expression=js_script):
return
js_script = "() => stopGlobalIncrementalObserver()"
await SkyvernFrame.evaluate(frame=self.skyvern_frame.get_frame(), expression=js_script)