Skip to content

fix: cancel all animations on page before running axe-core JS - #366

Merged
eoinkelly merged 1 commit into
mainfrom
cwac-352-axe-core-animations
Sep 6, 2026
Merged

eoinkelly merged 1 commit into
mainfrom
cwac-352-axe-core-animations

Conversation

@eoinkelly

@eoinkelly eoinkelly commented Sep 4, 2026

Copy link
Copy Markdown
Contributor

We noticed an issue with intermittent axe-core color-contrast false positive results on sites which animated in content at page load e.g. CSS like:

.hero {
  opacity: 0;
  transition: opacity .6s ease-out, transform .6s ease-out;
}
.hero.visible { opacity: 1 }

This change uses JS to forcibly cancel all active animations in the DOM just before the axe-core JS is run.

After a number of manual tests, this appears to fix the issue although it is hard to be 100% certain because the issue was intermittent.

@eoinkelly eoinkelly changed the title Forcibly cancel all animations on page before running axe-core JS bug: Cancel all animations on page before running axe-core JS Sep 4, 2026
@eoinkelly
eoinkelly marked this pull request as ready for review September 4, 2026 02:54
@eoinkelly
eoinkelly requested a lite review from Copilot September 4, 2026 03:09

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 Changes recommended

The new document.getAnimations() call can throw or be undefined in some browser contexts, causing the entire audit run to fail unless it’s guarded.

Once you've addressed the issues Copilot identified, you can request another Copilot review.

Pull request overview

This PR aims to reduce intermittent axe-core color-contrast false positives by stabilizing the DOM before running axe-core, specifically by canceling active animations right before axe.run(...) executes via Selenium’s execute_async_script.

Changes:

  • Injects a JavaScript pre-step to cancel all active DOM animations immediately before running axe.run(...).
File summaries
File Description
src/audit_plugins/axe_core_audit.py Adds a JS snippet to cancel active animations before invoking axe-core in the browser context.
Review details
  • Files reviewed: 1/1 changed files
  • Comments generated: 1
  • Review effort level: Lite

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

# that we cannot recover from, so exit the program.
sys.exit(1)
run_axe = (
'document.getAnimations().forEach(animation => animation.cancel());'

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We know exactly which browser and version we are using so this shouldn't be an issue.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

it's probably still not worth doing, but fwiw the AI suggestion here is overcomplicated:

document.getAnimations?.().forEach(animation => animation.cancel())

@eoinkelly
eoinkelly requested a review from G-Rath September 4, 2026 03:14
@G-Rath G-Rath changed the title bug: Cancel all animations on page before running axe-core JS fix: cancel all animations on page before running axe-core JS Sep 4, 2026

@G-Rath G-Rath left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

unrelated: we should probably rename the function to something like run_axe_core cause we're doing more than just "loading" it 😅

@eoinkelly
eoinkelly merged commit 7a1e38a into main Sep 6, 2026
13 checks passed
@eoinkelly
eoinkelly deleted the cwac-352-axe-core-animations branch September 6, 2026 21:07
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.

3 participants