1
0
mirror of https://github.com/gorhill/uBlock.git synced 2024-11-16 15:33:38 +01:00

Further improve prevent-fetch scriptlet

This commit is contained in:
Raymond Hill 2024-09-05 11:17:36 -04:00
parent 1dc09b6217
commit 60a009c530
No known key found for this signature in database
GPG Key ID: 25E1490B761470C2

View File

@ -2129,6 +2129,7 @@ builtinScriptlets.push({
fn: noFetchIf,
dependencies: [
'generate-content.fn',
'proxy-apply.fn',
'safe-self.fn',
],
});
@ -2175,14 +2176,10 @@ function noFetchIf(
responseProps.type = { value: responseType };
}
}
self.fetch = new Proxy(self.fetch, {
apply: function(target, thisArg, args) {
proxyApplyFn('fetch', function fetch(target, thisArg, args) {
const details = args[0] instanceof self.Request
? args[0]
: Object.assign({ url: args[0] }, args[1]);
if ( safe.logLevel > 1 ) {
safe.uboLog(logPrefix, `apply:\n\t${Object.entries(details).map(a => `${a[0]}: ${a[1]}`).join('\n\t')}`);
}
let proceed = true;
try {
const props = new Map();
@ -2195,9 +2192,11 @@ function noFetchIf(
if ( typeof v !== 'string' ) { continue; }
props.set(prop, v);
}
if ( propsToMatch === '' && responseBody === '' ) {
if ( safe.logLevel > 1 || propsToMatch === '' && responseBody === '' ) {
const out = Array.from(props).map(a => `${a[0]}:${a[1]}`);
safe.uboLog(logPrefix, `Called: ${out.join('\n')}`);
}
if ( propsToMatch === '' && responseBody === '' ) {
return Reflect.apply(target, thisArg, args);
}
proceed = needles.length === 0;
@ -2229,7 +2228,6 @@ function noFetchIf(
safe.Object_defineProperties(response, props);
return response;
});
}
});
}