1
0
mirror of https://github.com/gorhill/uBlock.git synced 2024-11-22 02:12:44 +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 redirectCount = 0;
let removeparamCount = 0;
let urlskipCount = 0;
let cspCount = 0;
let permissionsCount = 0;
let replaceCount = 0;
for ( let i = 0; i < requests.length; i++ ) {
const request = requests[i];
for ( const request of requests ) {
fctxt.setURL(request.url);
if ( fctxt.getIPAddress() === '' ) {
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) ) {
redirectCount += 1;
}
if ( fctxt.redirectURL !== undefined && sfne.hasQuery(fctxt) ) {
if ( sfne.filterQuery(fctxt, 'removeparam') ) {
if ( sfne.hasQuery(fctxt) ) {
if ( sfne.filterQuery(fctxt) ) {
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') ) {
cspCount += 1;
}
@ -207,9 +210,9 @@ export async function benchmarkStaticNetFiltering(options = {}) {
if ( sfne.redirectRequest(redirectEngine, fctxt) ) {
redirectCount += 1;
}
if ( fctxt.isRootDocument() && sfne.urlSkip(fctxt) ) {
urlskipCount += 1;
}
if ( fctxt.type === 'main_frame' ) {
sfne.matchAndFetchModifiers(fctxt, 'urlskip');
}
}
const t1 = performance.now();
@ -224,6 +227,7 @@ export async function benchmarkStaticNetFiltering(options = {}) {
`\tUnblocked: ${allowCount}`,
`\tredirect=: ${redirectCount}`,
`\tremoveparam=: ${removeparamCount}`,
`\turlskip=: ${urlskipCount}`,
`\tcsp=: ${cspCount}`,
`\tpermissions=: ${permissionsCount}`,
`\treplace=: ${replaceCount}`,

View File

@ -942,6 +942,9 @@ const PageStore = class {
if ( staticNetFilteringEngine.hasQuery(fctxt) ) {
staticNetFilteringEngine.filterQuery(fctxt, directives);
}
if ( this.urlSkippableResources.has(fctxt.itype) ) {
staticNetFilteringEngine.urlSkip(fctxt, directives);
}
if ( directives.length === 0 ) { return; }
if ( logger.enabled !== true ) { return; }
fctxt.pushFilters(directives.map(a => a.logData()));
@ -1132,22 +1135,30 @@ const PageStore = class {
response.blockedResources =
this.netFilteringCache.lookupAllBlocked(fctxt.getDocHostname());
}
};
PageStore.prototype.cacheableResults = new Set([
µb.FilteringContext.SUB_FRAME,
cacheableResults = new Set([
µb.FilteringContext.SUB_FRAME
]);
PageStore.prototype.collapsibleResources = new Set([
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
PageStore.junkyard = [];
PageStore.junkyardMax = 10;
static junkyard = [];
static junkyardMax = 10;
};
/******************************************************************************/

View File

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

View File

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