mirror of https://github.com/gorhill/uBlock.git
Further improve `prevent-fetch` scriptlet
This commit is contained in:
parent
1dc09b6217
commit
60a009c530
|
@ -2129,6 +2129,7 @@ builtinScriptlets.push({
|
||||||
fn: noFetchIf,
|
fn: noFetchIf,
|
||||||
dependencies: [
|
dependencies: [
|
||||||
'generate-content.fn',
|
'generate-content.fn',
|
||||||
|
'proxy-apply.fn',
|
||||||
'safe-self.fn',
|
'safe-self.fn',
|
||||||
],
|
],
|
||||||
});
|
});
|
||||||
|
@ -2175,14 +2176,10 @@ function noFetchIf(
|
||||||
responseProps.type = { value: responseType };
|
responseProps.type = { value: responseType };
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
self.fetch = new Proxy(self.fetch, {
|
proxyApplyFn('fetch', function fetch(target, thisArg, args) {
|
||||||
apply: function(target, thisArg, args) {
|
|
||||||
const details = args[0] instanceof self.Request
|
const details = args[0] instanceof self.Request
|
||||||
? args[0]
|
? args[0]
|
||||||
: Object.assign({ url: args[0] }, args[1]);
|
: 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;
|
let proceed = true;
|
||||||
try {
|
try {
|
||||||
const props = new Map();
|
const props = new Map();
|
||||||
|
@ -2195,9 +2192,11 @@ function noFetchIf(
|
||||||
if ( typeof v !== 'string' ) { continue; }
|
if ( typeof v !== 'string' ) { continue; }
|
||||||
props.set(prop, v);
|
props.set(prop, v);
|
||||||
}
|
}
|
||||||
if ( propsToMatch === '' && responseBody === '' ) {
|
if ( safe.logLevel > 1 || propsToMatch === '' && responseBody === '' ) {
|
||||||
const out = Array.from(props).map(a => `${a[0]}:${a[1]}`);
|
const out = Array.from(props).map(a => `${a[0]}:${a[1]}`);
|
||||||
safe.uboLog(logPrefix, `Called: ${out.join('\n')}`);
|
safe.uboLog(logPrefix, `Called: ${out.join('\n')}`);
|
||||||
|
}
|
||||||
|
if ( propsToMatch === '' && responseBody === '' ) {
|
||||||
return Reflect.apply(target, thisArg, args);
|
return Reflect.apply(target, thisArg, args);
|
||||||
}
|
}
|
||||||
proceed = needles.length === 0;
|
proceed = needles.length === 0;
|
||||||
|
@ -2229,7 +2228,6 @@ function noFetchIf(
|
||||||
safe.Object_defineProperties(response, props);
|
safe.Object_defineProperties(response, props);
|
||||||
return response;
|
return response;
|
||||||
});
|
});
|
||||||
}
|
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue