Skip to main content
🎉 A11y Issue Detection Agent is now live! Detect accessibility issues like a WCAG expert with AI. Try now!
No Result Found
Connect & Get help from 6000+ developers on our Discord community. Ask the CommunityAsk the Community

Get started with the npm plugin

Install and run the BrowserStack Accessibility DevTools npm package to scan React and HTML files for accessibility issues in your existing npm workflow.

The @browserstack/accessibility-devtools npm package integrates accessibility scanning directly into your existing npm-based workflow. As it requires no separate binary installation, it fits seamlessly into CI/CD pipelines and local developer setups. Just run npm install and you’re ready to go.

Prerequisites

  • Node.js 16 or later.
  • A BrowserStack account. If you don’t have one, sign up for free.
  • Your BrowserStack Username and Access Key from the Account & Profile page.

Supported file types

The npm plugin supports the following file types:

  • React: .js, .jsx, .tsx
  • HTML: .html

Set up authentication

To set up authentication, you need to add your credentials in both your local system and your CI/CD tool.

Local setup

Set up your BrowserStack credentials as environment variables in your shell configuration file:

export BROWSERSTACK_USERNAME=<your-username>
export BROWSERSTACK_ACCESS_KEY=<your-access-key>
export BROWSERSTACK_USERNAME=<your-username>
export BROWSERSTACK_ACCESS_KEY=<your-access-key>
set -x BROWSERSTACK_USERNAME <your-username>
set -x BROWSERSTACK_ACCESS_KEY <your-access-key>

CI/CD setup

Store your credentials as secrets in your CI/CD platform and inject them as environment variables into the build environment.

The exact steps to inject environment variables depend on your CI/CD platform. Refer to your platform’s documentation. For example, see GitHub Actions encrypted secrets or GitLab CI/CD variables.

Run accessibility checks

You can run accessibility checks using the CLI or the Node.js API:

Run the linter directly from your terminal using npx:

npx @browserstack/accessibility-devtools -i src/**/*.tsx

You can also integrate it into Git pre-commit hooks or build scripts for automated checks.

CLI options

Option Description
--version Show the version number.
--include or -i Global pattern(s) for files to lint.
--exclude or -e Global pattern(s) for files to exclude from linting.
--username or -u BrowserStack username. If not provided, the BROWSERSTACK_USERNAME environment variable is used.
--access-key or -k BrowserStack access key. If not provided, the BROWSERSTACK_ACCESS_KEY environment variable is used.
--non-strict or -n Print violations but do not exit with a non-success code.
--help Show help.

By default, the linter exits with a non-success code when it detects accessibility issues, which causes CI/CD builds to fail. Pass --non-strict (or -n) to print violations without exiting with a non-success code. Use this mode during initial onboarding to review issues without blocking your build.

Exit codes

Code Description
0 No accessibility issues found.
1 Accessibility issues detected.
2 BrowserStack connection issues.

Install the package as a dev dependency in your project:

npm install @browserstack/accessibility-devtools --save-dev

Use the exported function in custom Node.js build scripts. For example, with Gulp or other task runners:

import runA11yDevtools from '@browserstack/accessibility-devtools';

runA11yDevtools({
  include: ['src/**/*.jsx'],
  exclude: [],
  browserstackUsername: 'your_username',
  browserstackAccessKey: 'your_access_key',
});

API parameters

Property Type Required Description
include string[] Yes Global pattern(s) for files to lint.
browserstackUsername string Yes Your BrowserStack account username.
browserstackAccessKey string Yes Your BrowserStack account access key.
exclude string[] No Global pattern(s) for files to exclude from linting.
nonStrict boolean No Print violations but do not exit with a non-success code. Default: false.

Return value

The function returns a Promise<RunStatus> that resolves to one of the following values:

Value Code Description
RunStatus.SUCCESS 0 No accessibility issues found.
RunStatus.FAILURE 1 Accessibility issues detected.
RunStatus.ERROR 2 BrowserStack connection issues.

We're sorry to hear that. Please share your feedback so we can do better

Contact our Support team for immediate help while we work on improving our docs.

We're continuously improving our docs. We'd love to know what you liked





Thank you for your valuable feedback

Is this page helping you?

Yes
No

We're sorry to hear that. Please share your feedback so we can do better

Contact our Support team for immediate help while we work on improving our docs.

We're continuously improving our docs. We'd love to know what you liked





Thank you for your valuable feedback!

Talk to an Expert
Download Copy Check Circle