-
Notifications
You must be signed in to change notification settings - Fork 9.5k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
core(crawlable-anchors): ignore event listeners, validate url #13105
core(crawlable-anchors): ignore event listeners, validate url #13105
Conversation
Not sure whether ignoring onclick behaviour completely is a good idea. Let me know. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not sure whether ignoring onclick behaviour completely is a good idea. Let me know.
Given we confirmed that search will only look at href
, we're ok with ignoring click events entirely since this audit is only concerned about search engine crawlability.
Currently the audit does these things:
- Ignore links with
role
set - Fail if href starts with
file:
- Fail if href is an empty string
- Ignore links with a
click
event listener - Fail if onclick has
javascript:void(0)
- Fail if onclick has
window.location/open
We want to drop items 4-6. Currently the PR drops 5-6 but not 4. Then you'll need to delete some tests which will newly fail.
Besides that, we can do a bit more to improve the audit (although if you don't want to tackle this part, we can do it in a new PR). As it is, this would pass:
<a href="http:://example.com">link</a>
Even though the URL is invalid (and thus definitely not crawlable). This is because we don't check href
for anything but that it is non-empty and not file:
. This should do the trick:
try {
new URL(rawHref, URL.finalUrl); // URL can gotten from the first parameter of the `audit` function
} catch {
return true;
}
@@ -57,12 +55,9 @@ class CrawlableAnchors extends Audit { | |||
if (rawHref.startsWith('mailto:')) return; | |||
|
|||
const windowLocationRegExp = /window\.location=/; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
can delete this too
Looking good! For the smoke test, you can just flip these test cases from expecting "passing" to "failure":
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for the assist!
Thanks for helping out @connorjclark . |
Summary
Related Issues/PRs
fixes #11818