Assume media elements with no Content-Length header to be of size 0

Related issue:
- https://github.com/uBlockOrigin/uBlock-issues/issues/543
This commit is contained in:
Raymond Hill 2019-04-24 08:30:54 -04:00
parent 72bbcdd93c
commit fff2bb6290
No known key found for this signature in database
GPG key ID: 25E1490B761470C2
2 changed files with 15 additions and 12 deletions

View file

@ -440,11 +440,11 @@ PageStore.prototype.toggleNetFilteringSwitch = function(url, scope, state) {
/******************************************************************************/ /******************************************************************************/
PageStore.prototype.injectLargeMediaElementScriptlet = function() { PageStore.prototype.injectLargeMediaElementScriptlet = function() {
this.largeMediaTimer = null; vAPI.tabs.injectScript(this.tabId, {
µb.scriptlets.injectDeep( file: '/js/scriptlets/load-large-media-interactive.js',
this.tabId, allFrames: true,
'load-large-media-interactive' runAt: 'document_idle',
); });
µb.contextMenu.update(this.tabId); µb.contextMenu.update(this.tabId);
}; };
@ -714,10 +714,10 @@ PageStore.prototype.filterLargeMediaElement = function(fctxt, size) {
this.largeMediaCount += 1; this.largeMediaCount += 1;
if ( this.largeMediaTimer === null ) { if ( this.largeMediaTimer === null ) {
this.largeMediaTimer = vAPI.setTimeout( this.largeMediaTimer = vAPI.setTimeout(( ) => {
this.injectLargeMediaElementScriptlet.bind(this), this.largeMediaTimer = null;
500 this.injectLargeMediaElementScriptlet();
); }, 500);
} }
if ( µb.logger.enabled ) { if ( µb.logger.enabled ) {

View file

@ -907,10 +907,13 @@ const injectCSP = function(fctxt, pageStore, responseHeaders) {
// "Block elements by size" // "Block elements by size"
const foilLargeMediaElement = function(fctxt, pageStore, responseHeaders) { const foilLargeMediaElement = function(fctxt, pageStore, responseHeaders) {
const i = headerIndexFromName('content-length', responseHeaders); let size = 0;
if ( i === -1 ) { return; } 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); const result = pageStore.filterLargeMediaElement(fctxt, size);
if ( result === 0 ) { return; } if ( result === 0 ) { return; }