npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

agnostic-axe

v3.0.3

Published

Framework agnostic accessibility auditing with axe-core

Downloads

526

Readme

agnostic-axe

Developer tool that continously observes the DOM to detect accessibility issues. Its audits are powered by axe-core.

Screenshot of an opened website, with accessibility issues displayed in the browser console

Basic Usage

This is all you need to start reporting accessibility issues to the browser console:

import('https://unpkg.com/agnostic-axe@3').then(
  ({ AxeObserver, logViolations }) => {
    const MyAxeObserver = new AxeObserver(logViolations)
    MyAxeObserver.observe(document)
  }
)

To try agnostic-axe on any site, paste the above code into the browser console.

When adding agnostic-axe to your project, be sure to only import it in your development environment. Else your application will use more resources than necessary. (Here's an example of how to do this with webpack)

API Details

AxeObserver constructor

Accepts one parameter:

  • violationsCallback (required). A function that is invoked with an array of violations, as reported by axe-core. To log violations to the console, simply pass the logViolations function exported by this module.

AxeObserver.observe

Accepts one parameter:

  • targetNode (required). A DOM node. AxeObserver audits this node, and continously monitors it for changes. If a change has been detected, AxeObserver audits the parts that have changed, and reports any new accessibility defects.

To observe multiple nodes, one can call the AxeObserver.observe method multiple times.

MyAxeObserver.observe(document.getElementById('react-main'))
MyAxeObserver.observe(document.getElementById('vue-header'))
MyAxeObserver.observe(document.getElementById('page-footer'))

AxeObserver.disconnect

Accepts no parameters.

Invoke this method to stop observing the DOM. This also clears the cache of violations that were already reported.

MyAxeObserver.disconnect()

Interacting with the axe-core API

The instance of axe-core used by agnostic-axe is exported by this module. Import it to interact with the axe-core API.

import('https://unpkg.com/agnostic-axe@3').then(
  ({ axeCoreInstance, AxeObserver, logViolations }) => {
    axeCoreInstance.registerPlugin(myPlugin)
    // ...
  }
)

Comparison with react-axe

Unlike framework specific implementations of axe-core, such as react-axe, agnostic-axe uses a MutationObserver to listen for changes directly in the DOM. This has two advantages:

  1. It works with all web frameworks, and with any of their versions. This is key, as for example, at the time of writing, react-axe does not work with the newer React features (function components and fragments), while agnostic-axe does supports them.
  2. It only runs audits if the actual DOM changes. This means it uses less resources than react-axe, which runs audits when components rerender, even if their output does not change.

agnostic-axe is optimized for performance. Its audits are small chunks of work that run in the browser's idle periods.