1
0
mirror of https://github.com/gorhill/uBlock.git synced 2024-11-06 02:42:33 +01:00

Add support to urlskip= media resources

Related feedback:
https://github.com/uBlockOrigin/uBlock-issues/issues/3206#issuecomment-2406777654
This commit is contained in:
Raymond Hill 2024-10-12 08:52:05 -04:00
parent 2c60bb3b07
commit ce9fc5dc14
No known key found for this signature in database
GPG Key ID: 25E1490B761470C2
4 changed files with 42 additions and 26 deletions

View File

@ -166,11 +166,11 @@ export async function benchmarkStaticNetFiltering(options = {}) {
let allowCount = 0; let allowCount = 0;
let redirectCount = 0; let redirectCount = 0;
let removeparamCount = 0; let removeparamCount = 0;
let urlskipCount = 0;
let cspCount = 0; let cspCount = 0;
let permissionsCount = 0; let permissionsCount = 0;
let replaceCount = 0; let replaceCount = 0;
for ( let i = 0; i < requests.length; i++ ) { for ( const request of requests ) {
const request = requests[i];
fctxt.setURL(request.url); fctxt.setURL(request.url);
if ( fctxt.getIPAddress() === '' ) { if ( fctxt.getIPAddress() === '' ) {
fctxt.setIPAddress('93.184.215.14\n2606:2800:21f:cb07:6820:80da:af6b:8b2c'); fctxt.setIPAddress('93.184.215.14\n2606:2800:21f:cb07:6820:80da:af6b:8b2c');
@ -186,12 +186,15 @@ export async function benchmarkStaticNetFiltering(options = {}) {
if ( sfne.transformRequest(fctxt) ) { if ( sfne.transformRequest(fctxt) ) {
redirectCount += 1; redirectCount += 1;
} }
if ( fctxt.redirectURL !== undefined && sfne.hasQuery(fctxt) ) { if ( sfne.hasQuery(fctxt) ) {
if ( sfne.filterQuery(fctxt, 'removeparam') ) { if ( sfne.filterQuery(fctxt) ) {
removeparamCount += 1; removeparamCount += 1;
} }
} }
if ( fctxt.type === 'main_frame' || fctxt.type === 'sub_frame' ) { if ( sfne.urlSkip(fctxt) ) {
urlskipCount += 1;
}
if ( fctxt.isDocument() ) {
if ( sfne.matchAndFetchModifiers(fctxt, 'csp') ) { if ( sfne.matchAndFetchModifiers(fctxt, 'csp') ) {
cspCount += 1; cspCount += 1;
} }
@ -207,9 +210,9 @@ export async function benchmarkStaticNetFiltering(options = {}) {
if ( sfne.redirectRequest(redirectEngine, fctxt) ) { if ( sfne.redirectRequest(redirectEngine, fctxt) ) {
redirectCount += 1; redirectCount += 1;
} }
} if ( fctxt.isRootDocument() && sfne.urlSkip(fctxt) ) {
if ( fctxt.type === 'main_frame' ) { urlskipCount += 1;
sfne.matchAndFetchModifiers(fctxt, 'urlskip'); }
} }
} }
const t1 = performance.now(); const t1 = performance.now();
@ -224,6 +227,7 @@ export async function benchmarkStaticNetFiltering(options = {}) {
`\tUnblocked: ${allowCount}`, `\tUnblocked: ${allowCount}`,
`\tredirect=: ${redirectCount}`, `\tredirect=: ${redirectCount}`,
`\tremoveparam=: ${removeparamCount}`, `\tremoveparam=: ${removeparamCount}`,
`\turlskip=: ${urlskipCount}`,
`\tcsp=: ${cspCount}`, `\tcsp=: ${cspCount}`,
`\tpermissions=: ${permissionsCount}`, `\tpermissions=: ${permissionsCount}`,
`\treplace=: ${replaceCount}`, `\treplace=: ${replaceCount}`,

View File

@ -942,6 +942,9 @@ const PageStore = class {
if ( staticNetFilteringEngine.hasQuery(fctxt) ) { if ( staticNetFilteringEngine.hasQuery(fctxt) ) {
staticNetFilteringEngine.filterQuery(fctxt, directives); staticNetFilteringEngine.filterQuery(fctxt, directives);
} }
if ( this.urlSkippableResources.has(fctxt.itype) ) {
staticNetFilteringEngine.urlSkip(fctxt, directives);
}
if ( directives.length === 0 ) { return; } if ( directives.length === 0 ) { return; }
if ( logger.enabled !== true ) { return; } if ( logger.enabled !== true ) { return; }
fctxt.pushFilters(directives.map(a => a.logData())); fctxt.pushFilters(directives.map(a => a.logData()));
@ -1132,23 +1135,31 @@ const PageStore = class {
response.blockedResources = response.blockedResources =
this.netFilteringCache.lookupAllBlocked(fctxt.getDocHostname()); this.netFilteringCache.lookupAllBlocked(fctxt.getDocHostname());
} }
cacheableResults = new Set([
µb.FilteringContext.SUB_FRAME
]);
collapsibleResources = new Set([
µb.FilteringContext.IMAGE,
µb.FilteringContext.MEDIA,
µb.FilteringContext.OBJECT,
µb.FilteringContext.SUB_FRAME,
]);
urlSkippableResources = new Set([
µb.FilteringContext.IMAGE,
µb.FilteringContext.MAIN_FRAME,
µb.FilteringContext.MEDIA,
µb.FilteringContext.OBJECT,
µb.FilteringContext.SUB_FRAME,
]);
// To mitigate memory churning
static junkyard = [];
static junkyardMax = 10;
}; };
PageStore.prototype.cacheableResults = new Set([
µb.FilteringContext.SUB_FRAME,
]);
PageStore.prototype.collapsibleResources = new Set([
µb.FilteringContext.IMAGE,
µb.FilteringContext.MEDIA,
µb.FilteringContext.OBJECT,
µb.FilteringContext.SUB_FRAME,
]);
// To mitigate memory churning
PageStore.junkyard = [];
PageStore.junkyardMax = 10;
/******************************************************************************/ /******************************************************************************/
export { PageStore }; export { PageStore };

View File

@ -5449,9 +5449,9 @@ StaticNetFilteringEngine.prototype.urlSkip = function(fctxt, out = []) {
return out; return out;
}; };
function urlSkip(directive, urlin, steps) { function urlSkip(directive, url, steps) {
try { try {
let urlout = urlin; let urlout = url;
for ( const step of steps ) { for ( const step of steps ) {
const urlin = urlout; const urlin = urlout;
const c0 = step.charCodeAt(0); const c0 = step.charCodeAt(0);

View File

@ -196,8 +196,9 @@ const onBeforeRootFrameRequest = function(fctxt) {
if ( trusted === false && pageStore !== null ) { if ( trusted === false && pageStore !== null ) {
if ( result !== 1 ) { if ( result !== 1 ) {
pageStore.redirectNonBlockedRequest(fctxt); pageStore.redirectNonBlockedRequest(fctxt);
} else {
pageStore.skipMainDocument(fctxt);
} }
pageStore.skipMainDocument(fctxt);
} }
if ( logger.enabled ) { if ( logger.enabled ) {