Skip to content

Refine headless support for userbar and accessibility checker #13224

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 5 commits into from
Jul 12, 2025

Conversation

laymonage
Copy link
Member

@laymonage laymonage commented Jul 10, 2025

There are some other race condition issues that cause Axe and the scroll restoration to not work on headless. This usually happens if the page contains other JS code that blocks the page load event, which means the document.readyState is interactive and the DOMContentLoaded event has been fired. An example of this can be found on the "Bolani" bread page, which has a YouTube embed that blocks the page load by a few seconds.

Fix this by ensuring axe.configure() is run immediately during init and not on every run (as per #13164 (comment)), and by waiting for the window.load event instead of document.DOMContentLoaded.

In addition, some unrelated minor improvements:

  • getWagtailMessage simplification per Implement scroll restoration for cross-domain preview iframes #13165 (comment)
  • Move accessibility checker template elements to outside the dialog
    • This allows the client-side code to call document.querySelector('wagtail-userbar').runAxe() multiple times on demand. Without this, the template element disappears after the first render of the results, because we wipe the content of the dialog. Without the template elements, runAxe bails out early.
  • Adding more docstrings to PreviewController methods that don't have them

TODO:

@laymonage laymonage force-pushed the fix/headless-userbar-fixes branch from d1eee75 to 5d11ba1 Compare July 10, 2025 16:45
This allows us to ensure Axe has the right config as soon as possible without having to run it first, and also avoids reconfiguration on every run which hopefully improves performance a bit
@laymonage laymonage force-pushed the fix/headless-userbar-fixes branch from 5d11ba1 to e95342e Compare July 11, 2025 08:30
… the userbar

and wait for the userbar to post the w-userbar:axe-ready message before
running the checks from the page editor.
There's no need for them to be within the dialog.

In fact, having them in the dialog could cause trouble if we reuse the dialog instance for subsequent runs, as the template elements will no longer be within the dialog after it's instantiated
Copy link
Member

@thibaudcolas thibaudcolas left a comment

Choose a reason for hiding this comment

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

I’d recommend to further defer include/exclude refinements so we can discuss what’s the need for this. When we designed those options I think the main goal was to allow changing one selector, nothing super complex. But worth revisiting.

@thibaudcolas thibaudcolas merged commit 3c72124 into wagtail:main Jul 12, 2025
18 of 19 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants