Skip to content

Commit 13f9275

Browse files
committed
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/
1 parent 87db640 commit 13f9275

File tree

1 file changed

+20
-13
lines changed

1 file changed

+20
-13
lines changed

assets/resources/scriptlets.js

Lines changed: 20 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -433,21 +433,28 @@
433433
}
434434
return true;
435435
};
436+
const pruner = function(o) {
437+
if ( log !== undefined ) {
438+
const json = JSON.stringify(o, null, 2);
439+
if ( reLogNeedle.test(json) ) {
440+
log('uBO:', location.hostname, json);
441+
}
442+
return o;
443+
}
444+
if ( mustProcess(o) === false ) { return o; }
445+
for ( const path of prunePaths ) {
446+
findOwner(o, path, true);
447+
}
448+
return o;
449+
};
436450
JSON.parse = new Proxy(JSON.parse, {
437451
apply: function() {
438-
const r = Reflect.apply(...arguments);
439-
if ( log !== undefined ) {
440-
const json = JSON.stringify(r, null, 2);
441-
if ( reLogNeedle.test(json) ) {
442-
log('uBO:', location.hostname, json);
443-
}
444-
return r;
445-
}
446-
if ( mustProcess(r) === false ) { return r; }
447-
for ( const path of prunePaths ) {
448-
findOwner(r, path, true);
449-
}
450-
return r;
452+
return pruner(Reflect.apply(...arguments));
453+
},
454+
});
455+
Response.prototype.json = new Proxy(Response.prototype.json, {
456+
apply: function() {
457+
return Reflect.apply(...arguments).then(o => pruner(o));
451458
},
452459
});
453460
})();

0 commit comments

Comments
 (0)