axe-core icon indicating copy to clipboard operation
axe-core copied to clipboard

Decorative images should be ignored by the region rule

Open professorplumb opened this issue 2 years ago • 4 comments

Product

axe-core

Question

Like many website operators, we use "marketing pixels" to track page hits and conversions. These are usually img tags with a height and width of 1 and a src URL which points to a marketing partner's site and through which affiliate metrics are tracked.

These might look something like

<img src="https://marketing.partner.com/path/to/tracking/script/123456789/?identifier=gobbledygook&amp;random=1594174352357287200&amp;url=https://my-page.url/&amp;other-identifier=asdfjkl" height="1" width="1" alt="" />

Since they're often created by a third-party script, the script usually auto-appends them to the body tag. Because they're not inside a landmark region, they're called out by axe-core's region rule.

My question is: is there any way to get axe-core to ignore these pixels being outside a landmark region? The purpose of the rule - to have all consumable content inside landmark regions for screen reader navigation - doesn't apply, since these pixels aren't intended to be viewed by any users at all. (Most have alt="" to cause screen readers to ignore them.)

I could see a few ways to update axe-core to accommodate this:

  1. Exclude any images with height="1" width="1" (or with alt="", or both) from the region rule.
  2. Allow users to pass "ignorable" rule/element pairings to axe-core: the above could be ignored by something like ignoreIfMatches: [{ rule: 'region', elementRegex: '/img src.*height="1" width="1".*\/>/' }].

I'm aware that we can also fix these violations by appending the pixel to e.g. the end of the main element instead of the body. We don't always control the script which adds them, though, and we'd love to be able to ignore these in our accessibility audits.

professorplumb avatar Sep 01 '23 18:09 professorplumb

Allow users to pass "ignorable" rule/element pairings to axe-core:

Doesn't the exclude context property work for your use-case? https://github.com/dequelabs/axe-core/blob/develop/doc/context.md#exclude-elements-from-test

sorin-davidoi avatar Sep 06 '23 10:09 sorin-davidoi

@professorplumb Unfortunately there is no way to tell axe-core to ignore a specific violation, nor is there a good way for axe-core to detect the purpose of these tracking pixels from the markup alone to know to exclude them from the rule itself.

But as @sorin-davidoi has suggested, one way you can have axe-core not report the issue is to use the exclude property of the context object and that will ignore the element completely from the run.

straker avatar Sep 06 '23 14:09 straker

You shouldn't have to exclude these elements. Axe-core is in error in failing these under the region rule. I think the real issue here is that decorative images aren't ignored by the region rule.

WilcoFiers avatar Sep 07 '23 12:09 WilcoFiers

Thanks @WilcoFiers - having the region rule ignore alt="" images (or perhaps, more generally, anything which is not part of the accessibility tree) outside of landmarks sounds like a good idea.

@straker @sorin-davidoi appreciate the reference to the exclude property. I'm aware of it, but AFAICT it can only exclude an element and its subtree from all rules, not a specific rule. The latter is what I was asking for, and it looks like axe doesn't currently support it. The fix @WilcoFiers is proposing will solve the problem which prompted this ticket though.

professorplumb avatar Sep 07 '23 14:09 professorplumb

We received a new +1 of this issue in a customer support ticket today

dbjorge avatar Apr 04 '24 18:04 dbjorge