fix wait for animation end (#3201)

This commit is contained in:
LawyZheng
2025-08-15 15:24:54 +08:00
committed by GitHub
parent 8d6ac61cc8
commit 654cdb14e4
3 changed files with 45 additions and 17 deletions

View File

@@ -2642,6 +2642,28 @@ async function getIncrementElements(wait_until_finished = true) {
return [Array.from(idToElement.values()), cleanedTreeList];
}
function isAnimationFinished() {
const animations = document.getAnimations({ subtree: true });
const unfinishedAnimations = animations.filter(
(a) => a.playState !== "finished",
);
if (!unfinishedAnimations || unfinishedAnimations.length == 0) {
return true;
}
const unfinishedAnimationsWithoutBlocked = unfinishedAnimations.filter(
(a) => {
const element = a.effect?.target;
if (!element) {
_jsConsoleLog("Unfinished animation without element:", a);
return false;
}
const result = getBlockElementUniqueID(element);
return !result[1];
},
);
return unfinishedAnimationsWithoutBlocked.length === 0;
}
/**
// How to run the code:

View File

@@ -557,7 +557,8 @@ async def scrape_web_unsafe(
try:
await page.wait_for_load_state("load", timeout=3000)
await SkyvernFrame.wait_for_animation_end(page)
skyvern_frame = await SkyvernFrame.create_instance(page)
await skyvern_frame.safe_wait_for_animation_end()
except Exception:
LOG.warning("Failed to wait for load state, will continue scraping", exc_info=True)