From 067ef5843c182c1fa08112dc0daff1276fc1ce29 Mon Sep 17 00:00:00 2001 From: Raymond Hill Date: Fri, 8 Nov 2019 09:30:59 -0500 Subject: [PATCH] Ensure that typeof of href attribute is `string` Related issue: - https://github.com/uBlockOrigin/uBlock-issues/issues/777 --- src/js/contentscript.js | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/src/js/contentscript.js b/src/js/contentscript.js index a78624b61..01ed23f47 100644 --- a/src/js/contentscript.js +++ b/src/js/contentscript.js @@ -1429,11 +1429,10 @@ vAPI.bootstrap = (function() { // https://github.com/chrisaljoudi/uBlock/issues/1143 // Find a link under the mouse, to try to avoid confusing new tabs // as nuisance popups. - let elem = ev.target; - while ( elem !== null && elem.localName !== 'a' ) { - elem = elem.parentElement; - } - if ( elem === null ) { return; } + // https://github.com/uBlockOrigin/uBlock-issues/issues/777 + // Mind that href may not be a string. + const elem = ev.target.closest('a[href]'); + if ( elem === null || typeof elem.href !== 'string' ) { return; } vAPI.messaging.send('contentscript', { what: 'maybeGoodPopup', url: elem.href || '',