Skip to content

Commit

Permalink
Fix/await dom updated before axe scan (#398)
Browse files Browse the repository at this point in the history
* Await DOM elements to be updated before running axeScan

* Add missing Intelligent case statement for getUrlMessage

---------

Co-authored-by: Wilson WeeSheng Khoo <[email protected]>
  • Loading branch information
younglim and Wilson WeeSheng Khoo authored Sep 10, 2024
1 parent b401bc6 commit d903b3f
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 0 deletions.
1 change: 1 addition & 0 deletions src/constants/common.ts
Original file line number Diff line number Diff line change
Expand Up @@ -242,6 +242,7 @@ export const getUrlMessage = (scanner: ScannerTypes): string => {
switch (scanner) {
case ScannerTypes.WEBSITE:
case ScannerTypes.CUSTOM:
case ScannerTypes.INTELLIGENT:
return 'Please enter URL of website: ';
case ScannerTypes.SITEMAP:
return 'Please enter URL or file path to sitemap, or drag and drop a sitemap file here: ';
Expand Down
23 changes: 23 additions & 0 deletions src/crawlers/commonCrawlerFunc.ts
Original file line number Diff line number Diff line change
Expand Up @@ -158,6 +158,29 @@ export const runAxeScript = async (
customFlowDetails,
selectors = [],
) => {
// Checking for DOM mutations before proceeding to scan
await page.evaluate(() => {
return new Promise((resolve) => {
let timeout;

const observer = new MutationObserver(() => {
clearTimeout(timeout);

timeout = setTimeout(() => {
observer.disconnect();
resolve('DOM stabilized after mutations.');
}, 1000);
});

timeout = setTimeout(() => {
observer.disconnect();
resolve('No mutations detected, exit from idle state');
}, 1000);

observer.observe(document, { childList: true, subtree: true, attributes: true });
});
});

await crawlee.playwrightUtils.injectFile(page, axeScript);

const results = await page.evaluate(
Expand Down

0 comments on commit d903b3f

Please sign in to comment.