diff --git a/src/js/messaging.js b/src/js/messaging.js index bf4fdfb53..6d0db28f3 100644 --- a/src/js/messaging.js +++ b/src/js/messaging.js @@ -388,8 +388,12 @@ var onMessage = function(request, sender, callback) { pageStore = µb.pageStoreFromTabId(request.tabId); if ( pageStore !== null ) { pageStore.hiddenElementCount = 0; - pageStore.inlineScriptCount = 0; - µb.scriptlets.injectDeep(request.tabId, 'dom-survey'); + pageStore.scriptCount = 0; + vAPI.tabs.injectScript(request.tabId, { + allFrames: true, + file: '/js/scriptlets/dom-survey.js', + runAt: 'document_end' + }); } break; @@ -494,7 +498,7 @@ var onMessage = function(request, sender, callback) { if ( pageStore === null ) { break; } let tabContext = µb.tabContextManager.lookup(tabId); if ( tabContext === null ) { break; } - if ( pageStore.filterScripting(tabContext.rootHostname) ) { + if ( pageStore.filterScripting(tabContext.rootHostname, undefined) ) { vAPI.tabs.injectScript( tabId, { @@ -1263,7 +1267,7 @@ var domSurveyFinalReport = function(tabId) { what: 'domSurveyFinalReport', tabId: tabId, affectedElementCount: pageStore.hiddenElementCount, - scriptCount: pageStore.scriptCount + pageStore.inlineScriptCount, + scriptCount: pageStore.scriptCount, }); }; @@ -1312,14 +1316,14 @@ var onMessage = function(request, sender, callback) { if ( request.filteredElementCount ) { pageStore.hiddenElementCount += request.filteredElementCount; } - if ( request.inlineScriptCount ) { - pageStore.inlineScriptCount += request.inlineScriptCount; + if ( request.scriptCount ) { + pageStore.scriptCount += request.scriptCount; } let broadcastKey = tabId + '-domSurveyReport'; if ( broadcastTimers.has(broadcastKey) === false ) { broadcastTimers.set(broadcastKey, vAPI.setTimeout( ( ) => { domSurveyFinalReport(tabId); }, - 250 + 53 )); } } diff --git a/src/js/pagestore.js b/src/js/pagestore.js index 9d2141e32..4b45607ea 100644 --- a/src/js/pagestore.js +++ b/src/js/pagestore.js @@ -291,7 +291,6 @@ PageStore.prototype.init = function(tabId, context) { this.hiddenElementCount = ''; // Empty string means "unknown" this.remoteFontCount = 0; this.scriptCount = 0; - this.inlineScriptCount = 0; this.popupBlockedCount = 0; this.largeMediaCount = 0; this.largeMediaTimer = null; @@ -616,11 +615,11 @@ PageStore.prototype.filterRequest = function(context) { return 1; } - if ( requestType === 'script' ) { - this.scriptCount += 1; - if ( this.filterScripting(context.rootHostname) === 1 ) { - return 1; - } + if ( + requestType === 'script' && + this.filterScripting(context.rootHostname, true) === 1 + ) { + return 1; } var cacheableResult = this.cacheableResults[requestType] === true; @@ -720,9 +719,12 @@ PageStore.prototype.filterFont = function(context) { /******************************************************************************/ -PageStore.prototype.filterScripting = function(rootHostname) { +PageStore.prototype.filterScripting = function(rootHostname, netFiltering) { + if ( netFiltering === undefined ) { + netFiltering = this.getNetFilteringSwitch(); + } if ( - this.getNetFilteringSwitch() === false || + netFiltering === false || µb.hnSwitches.evaluateZ('no-scripting', rootHostname) === false ) { return 0; diff --git a/src/js/scriptlets/dom-survey.js b/src/js/scriptlets/dom-survey.js index 1bb5454e0..b00306807 100644 --- a/src/js/scriptlets/dom-survey.js +++ b/src/js/scriptlets/dom-survey.js @@ -47,6 +47,8 @@ inlineScriptCount = 1; } + let scriptTags = document.querySelectorAll('script[src]'); + let filteredElementCount = 0; if ( vAPI.domFilterer ) { filteredElementCount = vAPI.domFilterer.getFilteredElementCount(); @@ -58,7 +60,7 @@ what: 'domSurveyTransientReport', pageURL: window.location.href, filteredElementCount: filteredElementCount, - inlineScriptCount: inlineScriptCount, + scriptCount: inlineScriptCount + scriptTags.length, } ); })(); diff --git a/src/js/traffic.js b/src/js/traffic.js index 8984fd68e..63dd2f7c9 100644 --- a/src/js/traffic.js +++ b/src/js/traffic.js @@ -913,8 +913,8 @@ var injectCSP = function(pageStore, details) { let builtinDirectives = []; context.requestType = 'script'; - if ( pageStore.filterScripting(context.rootHostname) === 1 ) { - builtinDirectives.push("script-src *"); + if ( pageStore.filterScripting(context.rootHostname, true) === 1 ) { + builtinDirectives.push("script-src http: https:"); if ( loggerEnabled === true ) { logger.writeOne( tabId,