Skip to content

Commit

Permalink
Fix/improve xml-prune scriptlet
Browse files Browse the repository at this point in the history
  • Loading branch information
gorhill committed Aug 20, 2023
1 parent b1f0c5b commit 4b83101
Showing 1 changed file with 21 additions and 10 deletions.
31 changes: 21 additions & 10 deletions assets/resources/scriptlets.js
Expand Up @@ -2580,18 +2580,29 @@ function xmlPrune(
};
self.fetch = new Proxy(self.fetch, {
apply: function(target, thisArg, args) {
const fetchPromise = Reflect.apply(target, thisArg, args);
if ( reUrl.test(urlFromArg(args[0])) === false ) {
return Reflect.apply(target, thisArg, args);
return fetchPromise;
}
return safe.fetch(...args).then(realResponse =>
realResponse.text().then(text =>
new Response(pruneFromText(text), {
status: realResponse.status,
statusText: realResponse.statusText,
headers: realResponse.headers,
})
)
);
return fetchPromise.then(responseBefore => {
const response = responseBefore.clone();
return response.text().then(text => {
const responseAfter = new Response(pruneFromText(text), {
status: responseBefore.status,
statusText: responseBefore.statusText,
headers: responseBefore.headers,
});
Object.defineProperties(responseAfter, {
ok: { value: responseBefore.ok },
redirected: { value: responseBefore.redirected },
type: { value: responseBefore.type },
url: { value: responseBefore.url },
});
return responseAfter;
}).catch(( ) =>
responseBefore
);
});
}
});
self.XMLHttpRequest.prototype.open = new Proxy(self.XMLHttpRequest.prototype.open, {
Expand Down

0 comments on commit 4b83101

Please sign in to comment.