mirror of
https://github.com/gorhill/uBlock.git
synced 2024-10-04 08:37:11 +02:00
Support logging details of calls to json-prune-fetch-response
Example: example.com##+js(json-prune-fetch-response) This will output to the logger details of all fetch() with a Response.json() call. Related discussion: https://github.com/uBlockOrigin/uAssets/discussions/22556
This commit is contained in:
parent
fef26e234d
commit
e527a8f9af
@ -1198,10 +1198,10 @@ function jsonPruneFetchResponseFn(
|
|||||||
const extraArgs = safe.getExtraArgs(Array.from(arguments), 2);
|
const extraArgs = safe.getExtraArgs(Array.from(arguments), 2);
|
||||||
const propNeedles = parsePropertiesToMatch(extraArgs.propsToMatch, 'url');
|
const propNeedles = parsePropertiesToMatch(extraArgs.propsToMatch, 'url');
|
||||||
const stackNeedle = safe.initPattern(extraArgs.stackToMatch || '', { canNegate: true });
|
const stackNeedle = safe.initPattern(extraArgs.stackToMatch || '', { canNegate: true });
|
||||||
|
const logall = rawPrunePaths === '';
|
||||||
const applyHandler = function(target, thisArg, args) {
|
const applyHandler = function(target, thisArg, args) {
|
||||||
const fetchPromise = Reflect.apply(target, thisArg, args);
|
const fetchPromise = Reflect.apply(target, thisArg, args);
|
||||||
if ( rawPrunePaths === '' ) { return fetchPromise; }
|
let outcome = logall ? 'nomatch' : 'match';
|
||||||
let outcome = 'match';
|
|
||||||
if ( propNeedles.size !== 0 ) {
|
if ( propNeedles.size !== 0 ) {
|
||||||
const objs = [ args[0] instanceof Object ? args[0] : { url: args[0] } ];
|
const objs = [ args[0] instanceof Object ? args[0] : { url: args[0] } ];
|
||||||
if ( objs[0] instanceof Request ) {
|
if ( objs[0] instanceof Request ) {
|
||||||
@ -1218,14 +1218,18 @@ function jsonPruneFetchResponseFn(
|
|||||||
outcome = 'nomatch';
|
outcome = 'nomatch';
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if ( outcome === 'nomatch' ) { return fetchPromise; }
|
if ( logall === false && outcome === 'nomatch' ) { return fetchPromise; }
|
||||||
if ( safe.logLevel > 1 ) {
|
if ( safe.logLevel > 1 && outcome !== 'nomatch' && propNeedles.size !== 0 ) {
|
||||||
safe.uboLog(logPrefix, `Matched optional "propsToMatch"\n${extraArgs.propsToMatch}`);
|
safe.uboLog(logPrefix, `Matched optional "propsToMatch"\n${extraArgs.propsToMatch}`);
|
||||||
}
|
}
|
||||||
return fetchPromise.then(responseBefore => {
|
return fetchPromise.then(responseBefore => {
|
||||||
const response = responseBefore.clone();
|
const response = responseBefore.clone();
|
||||||
return response.json().then(objBefore => {
|
return response.json().then(objBefore => {
|
||||||
if ( typeof objBefore !== 'object' ) { return responseBefore; }
|
if ( typeof objBefore !== 'object' ) { return responseBefore; }
|
||||||
|
if ( logall ) {
|
||||||
|
safe.uboLog(logPrefix, safe.JSON_stringify(objBefore, null, 2));
|
||||||
|
return responseBefore;
|
||||||
|
}
|
||||||
const objAfter = objectPruneFn(
|
const objAfter = objectPruneFn(
|
||||||
objBefore,
|
objBefore,
|
||||||
rawPrunePaths,
|
rawPrunePaths,
|
||||||
|
Loading…
Reference in New Issue
Block a user