Skip to content

fix(snapshot): clean up stale highlight overlays before each snapshot#194

Open
Hexthebaldy wants to merge 1 commit intoepiral:mainfrom
Hexthebaldy:fix/stale-highlight-cleanup
Open

fix(snapshot): clean up stale highlight overlays before each snapshot#194
Hexthebaldy wants to merge 1 commit intoepiral:mainfrom
Hexthebaldy:fix/stale-highlight-cleanup

Conversation

@Hexthebaldy
Copy link
Copy Markdown

Closes #173

Problem

When running snapshot -i multiple times on a single page (common in
SPAs with client-side navigation), old highlight overlays accumulate
inside the playwright-highlight-container. The container is reused
across invocations but never cleared, so previous highlight boxes and
their scroll/resize event listeners pile up.
snapshot 1:
image

snapshot 2:
image
twitter space is closed yet old highlight boxes remains

Solution

At the top of buildDomTree(), remove the existing highlight container
and run all stored cleanup functions before building the new tree. This
ensures each snapshot starts clean regardless of how many times it has
been called on the same page.

Also i moved the HIGHLIGHT_CONTAINER_ID constant declaration earlier in
the function

After fix: stale highlights cleaned up on re-snapshot

snapshot 1:
image

close twitter space

snapshot 2:
image

@SeeYouAgain2018
Copy link
Copy Markdown

Have you tried these ref IDs? Can they accurately perform the click operation?

@Hexthebaldy
Copy link
Copy Markdown
Author

Have you tried these ref IDs? Can they accurately perform the click operation?

Yes, I've used these ref IDs and they reliably perform clicks.
The reason I opened this PR is a different problem: after multiple snapshot -i calls on the same page, old highlight overlays stack on top of new ones, and the index labels become completely unreadable.I can't clearly tell the agent which numberd element to click

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug] Stale highlight boxes accumulate in SPAs after multiple snapshot commands

2 participants