Make json-prune scriptlet also trap Response.json() calls

Related discussion:
- https://www.reddit.com/r/uBlockOrigin/comments/jns1t4/white_screen_skip_ad_on_youtube/gbg4aq8/
This commit is contained in:
Raymond Hill 2020-11-08 08:45:33 -05:00
parent 87db640653
commit 13f92756be
No known key found for this signature in database
GPG Key ID: 25E1490B761470C2
1 changed files with 20 additions and 13 deletions

View File

@ -433,21 +433,28 @@
}
return true;
};
const pruner = function(o) {
if ( log !== undefined ) {
const json = JSON.stringify(o, null, 2);
if ( reLogNeedle.test(json) ) {
log('uBO:', location.hostname, json);
}
return o;
}
if ( mustProcess(o) === false ) { return o; }
for ( const path of prunePaths ) {
findOwner(o, path, true);
}
return o;
};
JSON.parse = new Proxy(JSON.parse, {
apply: function() {
const r = Reflect.apply(...arguments);
if ( log !== undefined ) {
const json = JSON.stringify(r, null, 2);
if ( reLogNeedle.test(json) ) {
log('uBO:', location.hostname, json);
}
return r;
}
if ( mustProcess(r) === false ) { return r; }
for ( const path of prunePaths ) {
findOwner(r, path, true);
}
return r;
return pruner(Reflect.apply(...arguments));
},
});
Response.prototype.json = new Proxy(Response.prototype.json, {
apply: function() {
return Reflect.apply(...arguments).then(o => pruner(o));
},
});
})();