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() {
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 ) {

View File

@ -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; }