From 13f92756befaa9a8d3ba1615bd7abc7075758c67 Mon Sep 17 00:00:00 2001 From: Raymond Hill Date: Sun, 8 Nov 2020 08:45:33 -0500 Subject: [PATCH] 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/ --- assets/resources/scriptlets.js | 33 ++++++++++++++++++++------------- 1 file changed, 20 insertions(+), 13 deletions(-) diff --git a/assets/resources/scriptlets.js b/assets/resources/scriptlets.js index 5152c3d49..7875ec461 100644 --- a/assets/resources/scriptlets.js +++ b/assets/resources/scriptlets.js @@ -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)); }, }); })();