From 3b53c3a3e3ebc225411bfdbf5df4d2bb922c3125 Mon Sep 17 00:00:00 2001 From: Raymond Hill Date: Tue, 9 Nov 2021 15:18:30 -0500 Subject: [PATCH] Further improve GA's surrogate script Related issue: - https://github.com/AdguardTeam/Scriptlets/issues/154 Related discussion: - https://github.com/uBlockOrigin/uBlock-issues/issues/1807 --- .../google-analytics_ga.js | 20 ++++++++++++++----- 1 file changed, 15 insertions(+), 5 deletions(-) diff --git a/src/web_accessible_resources/google-analytics_ga.js b/src/web_accessible_resources/google-analytics_ga.js index d9ec2e4f4..c969b381c 100644 --- a/src/web_accessible_resources/google-analytics_ga.js +++ b/src/web_accessible_resources/google-analytics_ga.js @@ -46,7 +46,10 @@ /(^|\.)_link$/.test(a[0]) && typeof a[1] === 'string' ) { - window.location.assign(a[1]); + try { + window.location.assign(a[1]); + } catch(ex) { + } } // https://github.com/gorhill/uBlock/issues/2162 if ( a[0] === '_set' && a[1] === 'hitCallback' && typeof a[2] === 'function' ) { @@ -62,7 +65,7 @@ '_cookiePathCopy _deleteCustomVar _getName _setAccount', '_getAccount _getClientInfo _getDetectFlash _getDetectTitle', '_getLinkerUrl _getLocalGifPath _getServiceMode _getVersion', - '_getVisitorCustomVar _initData _link _linkByPost', + '_getVisitorCustomVar _initData _linkByPost', '_setAllowAnchor _setAllowHash _setAllowLinker _setCampContentKey', '_setCampMediumKey _setCampNameKey _setCampNOKey _setCampSourceKey', '_setCampTermKey _setCampaignCookieTimeout _setCampaignTrack _setClientInfo', @@ -74,13 +77,20 @@ '_trackPageview _trackSocial _trackTiming _trackTrans', '_visitCode' ].join(' ').split(/\s+/); - let i = api.length; - while ( i-- ) { - out[api[i]] = noopfn; + for ( const method of api ) { + out[method] = noopfn; } out._getLinkerUrl = function(a) { return a; }; + // https://github.com/AdguardTeam/Scriptlets/issues/154 + out._link = function(a) { + if ( typeof a !== 'string' ) { return; } + try { + window.location.assign(a); + } catch(ex) { + } + }; return out; })(); //