Injecting Axe a11y tester

I would like to use Crawlee to crawl a bunch of internal sites and run the Axe accessibility scanner on each page. I figured out how to inject the script they reference in their getting started docs (https://github.com/dequelabs/axe-core#getting-started) using the
page.addInitScript
.

import { PlaywrightCrawler, Dataset } from 'crawlee';
import axe from 'axe-core';

const crawler = new PlaywrightCrawler({
    async requestHandler({ request, page, enqueueLinks, log }) {
        await page.addInitScript('./node_modules/axe-core/axe-min.js');

        const title = await page.title();
        log.info(`Title of ${request.loadedUrl} is '${title}'`);

        const results = await axe.run();
        console.log(results.violations)

        await Dataset.pushData({ title, url: request.loadedUrl });

        await enqueueLinks();
    },
});

await crawler.run(['https://dequeuniversity.com/demo/mars/']);

But every page after that throws this error.

INFO PlaywrightCrawler: Starting the crawl
INFO PlaywrightCrawler: Title of https://dequeuniversity.com/demo/mars/ is 'Mars Commuter: Travel to Mars for Work or Pleasure!'
WARN PlaywrightCrawler: Reclaiming failed request back to the list or queue. Required "window" or "document" globals not defined and cannot be deduced from the context. Either set the globals before running or pass in a valid Element. {"id":"9syPc5JbUuAjPx1","url":"https://dequeuniversity.com/demo/mars/","retryCount":1}

If I comment out the call to axe.run() the error goes away and things 'work'.

Any idea what could be causing this?
MarsCommuter - Your gateway to the Red Planet
GitHub
Accessibility engine for automated Web UI testing. Contribute to dequelabs/axe-core development by creating an account on GitHub.
Was this page helpful?