Register |  Login

WAVE Stand-alone API Documentation

System Requirements

Installation

Extract all API package files from your download link, then upload or transfer to your server. Install Puppeteer and all other core dependencies by running the following command in the directory containing the files:
npm install

If not previously installed, install Node.js and npm first. For Linux, it's best to use a NodeSource installer.

Depending on your operating system, you likely will need to install dependencies for the Chromium browser to run. Read details on finding and installing Chromium dependencies. On Debian/Ubuntu, the following command should install all required dependencies:
sudo apt-get install -y ca-certificates fonts-liberation libappindicator3-1 libasound2 libatk-bridge2.0-0 libatk1.0-0 libc6 libcairo2 libcups2 libdbus-1-3 libexpat1 libfontconfig1 libgbm1 libgcc1 libglib2.0-0 libgtk-3-0 libnspr4 libnss3 libpango-1.0-0 libpangocairo-1.0-0 libstdc++6 libx11-6 libx11-xcb1 libxcb1 libxcomposite1 libxcursor1 libxdamage1 libxext6 libxfixes3 libxi6 libxrandr2 libxrender1 libxss1 libxtst6 lsb-release wget xdg-utils

Start the WAVE API server using:
node waveserver.js

For most installations, it is recommended to instead run the WAVE API server using PM2. PM2 is a process manager that runs the WAVE Node process in the background so you do not need to be logged in to the server terminal / command line. Install with:
npm install -g pm2
then start the WAVE API server with:
pm2 start waveserver.js

You can monitor the WAVE server processing and debugging output using pm2 monit. Stop the server using pm2 stop waveserver.js.

By default, the server listens on 127.0.0.1:8888 and is accessible only from the local computer. API requests are made at http://127.0.0.1:8888/request?key=YOURAPIKEY&url=YOURURL. Query string values, including the page URL, must be URL-encoded. The default port can be changed by editing PORT in waveserver.js. The API key is defined in license/api.config.json. To allow remote access, configure a reverse proxy or change HOST in waveserver.js.

Access the WAVE API monitoring dashboard at http://127.0.0.1:8888/. Server status values (such as the number of queued and running requests and the number of active workers) can be monitored in JSON format at http://127.0.0.1:8888/status?json.

Configuring the WAVE Stand-alone API

API Query and Output Parameters

See https://wave.webaim.org/api/details for available request and output parameters and API usage details (you will, of course, need to modify the request URLs to point to your local installation). Additionally, the stand-alone API allows you to pass the additional parameters as defined above. If set, these will override any parameters set in the user.config.json file.

API Documentation and Objects

The WAVE Documentation API may be freely accessed via the public WAVE website as documented at https://wave.webaim.org/api/details#documentation. A JSON object for all WAVE items (including documentation) for use within your application can be provided upon request.

Pre-load and Post-load Scripts

Puppeteer scripts can be run before and after the page to be evaluated is loaded and rendered. Pre-load scripts allow you to perform processes such as logging in to a website or setting cookies or local storage data (perhaps with session information)—useful if the page to be evaluated requires authentication (complex authentication, such as two-factor, may not work directly). Post-load scripts allow you to manipulate page content, fill out forms, trigger error messages, trigger single-page app state changes, etc. before the page is analyzed by WAVE.

Scripts must be saved in the /scripts/ directory with a .js extension. The script template must be formatted as follows:

module.exports = async (page) => {
 YOUR PUPPETEER COMMANDS HERE
 return page;
};

To run pre- or post-load scripts, append the prescript and/or postscript GET parameters to your API request: request?key=YOURKEY&prescript=mypreloadscript.js&postscript=mypostloadscript.js&url=YOURURL

IMPORTANT: Puppeteer scripts provide full control of the Chromium browser within the API, so care should be taken in limiting access to trusted users.

Many examples of Puppeteer scripts are available at https://github.com/checkly/puppeteer-examples.

Export one asynchronous function that accepts the existing Puppeteer page object. Do not import Puppeteer, launch another browser, create another page, or close the browser. The API manages the browser and page lifecycle. Pre-load scripts will typically begin with a page.goto to open a page (such as a login page). Post-load scripts should not include page.goto, but should manipulate the content of or interact with the page being evaluated.

Prescript for logging in to a website

module.exports = async (page) => {
	await page.goto('https://mysite.com/login');
	await page.waitForSelector('#username');
	await page.type('#username', 'MyUsername');
	await page.waitForSelector('#password');
	await page.type('#password', 'MyP@55word');
	await page.click('.login-button');
	await page.waitForSelector('#maincontent');
	return page;
};

This prescript loads the login page, ensures that the username and password fields are available, types the username and password into the appropriate fields, clicks the login button (class="login-button"), and then waits for the id="maincontent" element to be loaded in the resulting page. The page to be evaluated will be loaded with the authentication and cookies in place.

Prescript for setting a site cookie

For sites that rely on cookies to verify authentication information, you can capture the cookie values via Developer Tools or by the EditThisCookie browser extension, then set this cookie data in a prescript.

module.exports = async (page) => {
	const cookie = {
		"domain": "webaim.org",
		"hostOnly": true,
		"httpOnly": false,
		"name": "sessionid",
		"path": "/",
		"sameSite": "no_restriction",
		"secure": false,
		"session": true,
		"storeId": "0",
		"value": "01234567890",
		"id": 1
	}
	
	await page.setCookie(cookie)
	return page;
};

With the sessionid cookie in place, you can then evaluate pages on the site that would otherwise require separate authentication.

Prescript for setting Local Storage session data

Some sites use Local Storage, rather than cookies, to store authentication data. This can also be captured and injected before the page is evaluated.

module.exports = async (page) => {
	let json ={"currentUser":"{\"username\":\"username@domain.org\",\"token\":\"eyJ0eXAiOiJKV1QiLCJhbGciOi\"}"};
	
	await page.evaluateOnNewDocument(json => {
		localStorage.clear();
		for (let key in json)
			localStorage.setItem(key, json[key]);
		}, json);
	return page;
};

With the session data in place, you can then evaluate pages on the site that would otherwise require authentication.

Postscript for manipulating page content

module.exports = async (page) => {
	await page.waitForSelector('#search');
	await page.type('#search', 'John');
	await page.click('#search-button');
	await page.waitForSelector('#search-results');
	await page.click('#search-results > div > .details:nth-child(4)');
	await new Promise(resolve => setTimeout(resolve, 1000));
	return page;
};

This Puppeteer script will wait for the id="search" input element, enter the word "John" into this field, click the search button, wait for the search results element, then click the fourth button (with class="details"), and then wait 1000 milliseconds for the details dialog to appear. After the postscript has completed, the API will wait evaldelay milliseconds (default 250) before analyzing the page.

Scripts are currently experimental! They may significantly increase API processing time and may result in errors, especially if the page content is lost or changes during API analysis.

Terms of Use

By licensing the WAVE Accessibility Tool stand-alone online web service, API, and/or related systems (hereafter referred to as WAVE), you acknowledge that you have read, understood, and agree to be bound by the WAVE Terms of Use for your license.