From fff2bb62904ee40b8d13375f3a6158d99e33837e Mon Sep 17 00:00:00 2001 From: Raymond Hill Date: Wed, 24 Apr 2019 08:30:54 -0400 Subject: [PATCH] Assume media elements with no Content-Length header to be of size 0 Related issue: - https://github.com/uBlockOrigin/uBlock-issues/issues/543 --- src/js/pagestore.js | 18 +++++++++--------- src/js/traffic.js | 9 ++++++--- 2 files changed, 15 insertions(+), 12 deletions(-) diff --git a/src/js/pagestore.js b/src/js/pagestore.js index a3e2e6a46..868f8b8ac 100644 --- a/src/js/pagestore.js +++ b/src/js/pagestore.js @@ -440,11 +440,11 @@ PageStore.prototype.toggleNetFilteringSwitch = function(url, scope, state) { /******************************************************************************/ PageStore.prototype.injectLargeMediaElementScriptlet = function() { - this.largeMediaTimer = null; - µb.scriptlets.injectDeep( - this.tabId, - 'load-large-media-interactive' - ); + vAPI.tabs.injectScript(this.tabId, { + file: '/js/scriptlets/load-large-media-interactive.js', + allFrames: true, + runAt: 'document_idle', + }); µb.contextMenu.update(this.tabId); }; @@ -714,10 +714,10 @@ PageStore.prototype.filterLargeMediaElement = function(fctxt, size) { this.largeMediaCount += 1; if ( this.largeMediaTimer === null ) { - this.largeMediaTimer = vAPI.setTimeout( - this.injectLargeMediaElementScriptlet.bind(this), - 500 - ); + this.largeMediaTimer = vAPI.setTimeout(( ) => { + this.largeMediaTimer = null; + this.injectLargeMediaElementScriptlet(); + }, 500); } if ( µb.logger.enabled ) { diff --git a/src/js/traffic.js b/src/js/traffic.js index 0ddd3dfc9..65a0048da 100644 --- a/src/js/traffic.js +++ b/src/js/traffic.js @@ -907,10 +907,13 @@ const injectCSP = function(fctxt, pageStore, responseHeaders) { // "Block elements by size" const foilLargeMediaElement = function(fctxt, pageStore, responseHeaders) { - const i = headerIndexFromName('content-length', responseHeaders); - if ( i === -1 ) { return; } + let size = 0; + if ( µBlock.userSettings.largeMediaSize !== 0 ) { + const i = headerIndexFromName('content-length', responseHeaders); + if ( i === -1 ) { return; } + size = parseInt(responseHeaders[i].value, 10) || 0; + } - const size = parseInt(responseHeaders[i].value, 10) || 0; const result = pageStore.filterLargeMediaElement(fctxt, size); if ( result === 0 ) { return; }