Error Handling in Puppeteer

Link to Error Handling in Puppeteer copied to clipboard

How to work around common errors seen in axe DevTools HTML for Puppeteer

Version 4.3.0 and above of the axe DevTools HTML integrations use a new technique when calling AxeDevToolsPuppeteer.analyze() which opens a new window at the end of a run. Many of the issues outlined in this document address common problems with this technique and their potential solutions.

Having Popup blockers enabled

Popup blockers prevent us from opening the new window when calling AxeDevToolsPuppeteer.analyze(). The default configuration for most automation testing libraries should allow popups. Please make sure that you do not explicitly enable popup blockers which may cause an issue while running the tests.

AxeDevToolsPuppeteer.setLegacyMode(legacy: boolean)

If for some reason you are unable to run the new AxeDevToolsPuppeteer.analyze technique without errors, axe provides a new chainable method that allows you to run the legacy version of AxeDevToolsPuppeteer.analyze. When using this method axe excludes accessibility issues that may occur in cross-domain frames and iframes.

note

AxeDevToolsPuppeteer.setLegacyMode is deprecated and will be removed in v5.0. Please report any errors you may have while running AxeDevToolsPuppeteer.analyze so that they can be fixed before the legacy version is removed.

Example

const { AxeDevToolsPuppeteer } = require('@axe-devtools/puppeteer');
const puppeteer = require('puppeteer');

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

  await page.goto('https://dequeuniversity.com/demo/mars/');

  try {
    const results = await new AxeDevToolsPuppeteer(page).setLegacyMode().analyze();
    console.log(results);
  } catch(err) {
      // do something with the error
  }
  await page.close();
  await browser.close();
})();