Skip to content

Commit

Permalink
Make json-prune scriptlet also trap Response.json() calls
Browse files Browse the repository at this point in the history
  • Loading branch information
gorhill committed Nov 8, 2020
1 parent 87db640 commit 13f9275
Showing 1 changed file with 20 additions and 13 deletions.
33 changes: 20 additions & 13 deletions assets/resources/scriptlets.js
Original file line number Diff line number Diff line change
Expand Up @@ -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));
},
});
})();
Expand Down

0 comments on commit 13f9275

Please sign in to comment.