diff --git a/lighthouse-core/audits/dobetterweb/external-anchors-use-rel-noopener.js b/lighthouse-core/audits/dobetterweb/external-anchors-use-rel-noopener.js index a7eb425f680a..c2ede2f2e069 100644 --- a/lighthouse-core/audits/dobetterweb/external-anchors-use-rel-noopener.js +++ b/lighthouse-core/audits/dobetterweb/external-anchors-use-rel-noopener.js @@ -47,6 +47,10 @@ class ExternalAnchorsUseRelNoopenerAudit extends Audit { return true; } }) + .filter(anchor => { + // Ignore href's that are not real links + return !anchor.href || !anchor.href.toLowerCase().startsWith('javascript:'); + }) .map(anchor => { return { href: anchor.href || 'Unknown', diff --git a/lighthouse-core/test/audits/dobetterweb/external-anchors-use-rel-noopener-test.js b/lighthouse-core/test/audits/dobetterweb/external-anchors-use-rel-noopener-test.js index a1b0237c500a..c89aab41e7c9 100644 --- a/lighthouse-core/test/audits/dobetterweb/external-anchors-use-rel-noopener-test.js +++ b/lighthouse-core/test/audits/dobetterweb/external-anchors-use-rel-noopener-test.js @@ -54,4 +54,16 @@ describe('External anchors use rel="noopener"', () => { assert.equal(auditResult.details.items.length, 3); assert.ok(auditResult.debugString, 'includes debugString'); }); + + it('does not fail for links with javascript in href attribute', () => { + const auditResult = ExternalAnchorsAudit.audit({ + AnchorsWithNoRelNoopener: [ + {href: 'javascript:void(0)'}, + {href: 'JAVASCRIPT:void(0)'}, + ], + URL: {finalUrl: URL}, + }); + assert.equal(auditResult.rawValue, true); + assert.equal(auditResult.details.items.length, 0); + }); });