dequelabs / axe-core

Accessibility engine for automated Web UI testing
https://www.deque.com/axe/
Mozilla Public License 2.0
5.89k stars 771 forks source link

getting document-title violation when scanned code uses title in head. #4512

Open jasonhocker opened 3 months ago

jasonhocker commented 3 months ago

Product

axe-core

Product Version

4.9.1

Latest Version

Issue Description

Expectation

Describe what you expected the product to do.

Actual

Using axe-core npm package scanning some text and getting document-title violation though there is a </p> <h4>How to Reproduce</h4> <pre><code> let parser = new DOMParser(); const html2 = '<html lang="en-US"><head><title>Deque test</title></head><body></body></html>'; let document = parser.parseFromString(html2, "text/html"); await axe.run(document, { runOnly: ['wcag2a', 'wcag2aa', 'wcag21a', 'wcag21aa'] }).then(results => {</code></pre> <h4>Additional context</h4> </div> </div> <div class="comment"> <div class="user"> <a rel="noreferrer nofollow" target="_blank" href="https://github.com/straker"><img src="https://avatars.githubusercontent.com/u/2433219?v=4" />straker</a> commented <strong> 3 months ago</strong> </div> <div class="markdown-body"> <p>Thanks for the issue. I can't reproduce the issue though. Running the code inside it's own bock doesn't reproduce the issue and I can't run it outside of it's own block because I can't override <code>document</code>.</p> <pre><code class="language-js">(async () => { let parser = new DOMParser(); const html2 = '<html lang="en-US"><head><title>Deque test</title></head><body></body></html>'; let document = parser.parseFromString(html2, "text/html"); const results = await axe.run(document, { runOnly: ['wcag2a', 'wcag2aa', 'wcag21a', 'wcag21aa'] }) console.log(results) // violations is empty })()</code></pre> <pre><code class="language-js"> let parser = new DOMParser(); const html2 = '<html lang="en-US"><head><title>Deque test</title></head><body></body></html>'; // throws Uncaught SyntaxError: Identifier 'document' has already been declared let document = parser.parseFromString(html2, "text/html"); </code></pre> </div> </div> <div class="comment"> <div class="user"> <a rel="noreferrer nofollow" target="_blank" href="https://github.com/jasonhocker"><img src="https://avatars.githubusercontent.com/u/1907146?v=4" />jasonhocker</a> commented <strong> 3 months ago</strong> </div> <div class="markdown-body"> <p>I am trying to write a Chrome extension for my own internal purpose. I am trying to run axe-core inside devtools, passing the html from the content-script in certain situations and then scan in devtools using a DOMParser to hydrate the string I get from the messaging to pass to axe-core. Looks like the extension is doing its job, but for this test it was scanning the head of the html for the devtools panel. Once I added a title to that, this violation from axe-core went away, but I'm wondering what is not getting scanned that I expected to scan.</p> </div> </div> <div class="page-bar-simple"> </div> <div class="footer"> <ul class="body"> <li>© <script> document.write(new Date().getFullYear()) </script> Githubissues.</li> <li>Githubissues is a development platform for aggregating issues.</li> </ul> </div> <script src="https://cdn.jsdelivr.net/npm/jquery@3.5.1/dist/jquery.min.js"></script> <script src="/githubissues/assets/js.js"></script> <script src="/githubissues/assets/markdown.js"></script> <script src="https://cdn.jsdelivr.net/gh/highlightjs/cdn-release@11.4.0/build/highlight.min.js"></script> <script src="https://cdn.jsdelivr.net/gh/highlightjs/cdn-release@11.4.0/build/languages/go.min.js"></script> <script> hljs.highlightAll(); </script> </body> </html>