Skip to content
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

fix(respondable): work with CDP Page.setDocumentContent #3921

Merged
merged 5 commits into from
Mar 7, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions doc/examples/puppeteer/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,12 @@
"private": true,
"main": "axe-puppeteer.js",
"scripts": {
"test": "node axe-puppeteer.js https://deque.com"
"test": "npm run test:url && npm run test:set-content",
"test:url": "node axe-puppeteer.js https://deque.com",
"test:set-content": "node set-content.js"
},
"devDependencies": {
"axe-core": "^4.6.2",
"puppeteer": "^19.5.0"
"puppeteer": "^19.7.2"
}
}
34 changes: 34 additions & 0 deletions doc/examples/puppeteer/set-content.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
const assert = require('assert');
const puppeteer = require('puppeteer');
const axe = require('axe-core');

(async () => {
const browser = await puppeteer.launch();
const page = await browser.newPage();

await page.setContent(`
<html lang="en">
<head>
<title>Test Page</title>
</head>
<body>
<main>
<h1>Hello World</h1>
<button id="empty-button"></button>
<iframe title="iframe" srcdoc="<button id='iframe-empty-button'></button>"></iframe>
</main>
</body>
</html>
`);

await page.evaluate(axe.source);
const frames = page.frames();
for (let i = 0; i < frames.length; i++) {
await frames[i].evaluate(axe.source);
}

const results = await page.evaluate(`window.axe.run()`);
assert(results.violations.length);

await browser.close();
})();
9 changes: 7 additions & 2 deletions lib/core/base/audit.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,16 @@ const dotRegex = /\{\{.+?\}\}/g;
function getDefaultOrigin() {
// @see https://html.spec.whatwg.org/multipage/webappapis.html#dom-origin-dev
// window.origin does not exist in ie11
if (window.origin) {
// prevent origin default "null" string on CDP `Page.setDocumentContent` https://chromedevtools.github.io/devtools-protocol/tot/Page/#method-setDocumentContent
if (window.origin && window.origin !== 'null') {
return window.origin;
}
// window.location does not exist in node when we run the build
if (window.location && window.location.origin) {
if (
window.location &&
window.location.origin &&
window.location.origin !== 'null'
) {
return window.location.origin;
}
}
Expand Down