Repository navigation
perf: only load axe-core when accessibility is asserted - #290
Merged
Merged
Conversation
The init script embedded axe.min.js (553 KB) into every page, so Chromium parsed and executed it on about:blank in newPage() and again on every document, although only assertNoAccessibilityIssues() uses it. axe-core is now injected right before axe.run() into the page and, recursively, into its iframes, so iframe content is still audited.
Both branches added tests/Browser/Webpage/AssertNoAccessibilityIssuesTest.php. The timeout test from pestphp#289 patched window.axe.run on the page's load event, which no longer runs before axe-core is injected, so it would pass without waiting. Its page now brings its own slow window.axe instead, which the assertion uses rather than injecting axe-core; the test still fails with the old fixed 5 second cap. The duplicate passing case from pestphp#289 is covered by the existing one.
Member
|
Thanks |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
InitScript::get()embeds the wholeaxe.min.js(553 KB) into the init script that everyvisit()registers on its browser context. Chromium therefore parses and executes axe-core inabout:blankwhen the page is created, and again in every document the page navigates to — although onlyassertNoAccessibilityIssues()ever useswindow.axe.Timing the steps of
PendingAwaitablePage::buildAwaitablePage()in a real app:addInitScript()newPage()Change
InitScriptkeeps only the console log / JS error capture.Page::injectAxe()evaluates axe-core into the page right beforeaxe.run(), only ifwindow.axeis not there yet, and recursively into its iframes, so iframe content is still audited exactly like before (the init script used to load axe into every frame).assertNoAccessibilityIssues()calls it after the existing load-state waits.The only observable difference:
window.axeis no longer present on pages untilassertNoAccessibilityIssues()has been called.Tests
There were no tests for
assertNoAccessibilityIssues(), so the first commit adds them against the current behaviour (all pass on5.x):image-alton an inaccessible one,The second commit adds the change and a test that axe is not loaded until the assertion runs (red on
5.x). Full suite: 351 passed, 27 skipped (onlyOnMac); type coverage 100 %; PHPStan, Pint and Rector clean.Benchmark
Linux, 4 vCPU, Playwright 1.63,
chromium-headless-shell.This repository: trivial page, median of 20 warm
visit('/')->assertSee(...), alternating runs:5.xA real Laravel + Inertia + React app (Mantine UI, ~3 MB Vite build):
5.xvisit()until content is visibleThe saving is roughly constant per page load (~250–300 ms), so it matters most for suites with many short browser tests.