Sha256: 48ac68ef6b638f88d92e8ff042280b4768df6e022beac460c9442cf5d2fe3864

Contents?: true

Size: 1.21 KB

Versions: 375

Compression:

Stored size: 1.21 KB

Contents

const puppeteer = require('puppeteer');
const axeCore = require('axe-core');
const { parse: parseURL } = require('url');
const assert = require('assert');

// Cheap URL validation
const isValidURL = input => {
	const u = parseURL(input);
	return u.protocol && u.host;
};

// node axe-puppeteer.js <url>
const url = process.argv[2];
assert(isValidURL(url), 'Invalid URL');

const main = async url => {
	let browser;
	let results;
	try {
		// Setup Puppeteer
		browser = await puppeteer.launch();

		// Get new page
		const page = await browser.newPage();
		await page.goto(url);

		// Inject and run axe-core
		const handle = await page.evaluateHandle(`
			// Inject axe source code
			${axeCore.source}
			// Run axe
			axe.run()
		`);

		// Get the results from `axe.run()`.
		results = await handle.jsonValue();
		// Destroy the handle & return axe results.
		await handle.dispose();
	} catch (err) {
		// Ensure we close the puppeteer connection when possible
		if (browser) {
			await browser.close();
		}

		// Re-throw
		throw err;
	}

	await browser.close();
	return results;
};

main(url)
	.then(results => {
		console.log(results);
	})
	.catch(err => {
		console.error('Error running axe-core:', err.message);
		process.exit(1);
	});

Version data entries

375 entries across 375 versions & 1 rubygems

Version Path
govuk_publishing_components-30.4.1 node_modules/axe-core/doc/examples/puppeteer/axe-puppeteer.js
govuk_publishing_components-30.4.0 node_modules/axe-core/doc/examples/puppeteer/axe-puppeteer.js
govuk_publishing_components-30.3.0 node_modules/axe-core/doc/examples/puppeteer/axe-puppeteer.js
govuk_publishing_components-30.2.1 node_modules/axe-core/doc/examples/puppeteer/axe-puppeteer.js
govuk_publishing_components-30.2.0 node_modules/axe-core/doc/examples/puppeteer/axe-puppeteer.js
govuk_publishing_components-30.1.0 node_modules/axe-core/doc/examples/puppeteer/axe-puppeteer.js
govuk_publishing_components-30.0.0 node_modules/axe-core/doc/examples/puppeteer/axe-puppeteer.js
govuk_publishing_components-29.15.3 node_modules/axe-core/doc/examples/puppeteer/axe-puppeteer.js
govuk_publishing_components-29.15.2 node_modules/axe-core/doc/examples/puppeteer/axe-puppeteer.js
govuk_publishing_components-29.15.1 node_modules/axe-core/doc/examples/puppeteer/axe-puppeteer.js
govuk_publishing_components-29.15.0 node_modules/axe-core/doc/examples/puppeteer/axe-puppeteer.js
govuk_publishing_components-29.14.0 node_modules/axe-core/doc/examples/puppeteer/axe-puppeteer.js
govuk_publishing_components-29.13.0 node_modules/axe-core/doc/examples/puppeteer/axe-puppeteer.js
govuk_publishing_components-29.12.1 node_modules/axe-core/doc/examples/puppeteer/axe-puppeteer.js
govuk_publishing_components-29.12.0 node_modules/axe-core/doc/examples/puppeteer/axe-puppeteer.js
govuk_publishing_components-29.11.0 node_modules/axe-core/doc/examples/puppeteer/axe-puppeteer.js
govuk_publishing_components-29.10.0 node_modules/axe-core/doc/examples/puppeteer/axe-puppeteer.js
govuk_publishing_components-29.9.0 node_modules/axe-core/doc/examples/puppeteer/axe-puppeteer.js
govuk_publishing_components-29.8.0 node_modules/axe-core/doc/examples/puppeteer/axe-puppeteer.js
govuk_publishing_components-29.7.0 node_modules/axe-core/doc/examples/puppeteer/axe-puppeteer.js