mirror of https://github.com/gorhill/uBlock.git
Fix/improve `xml-prune` scriptlet
Related issue: https://github.com/uBlockOrigin/uAssets/issues/14849#issuecomment-1257094491
This commit is contained in:
parent
b1f0c5b773
commit
4b83101ab9
|
@ -2580,18 +2580,29 @@ function xmlPrune(
|
||||||
};
|
};
|
||||||
self.fetch = new Proxy(self.fetch, {
|
self.fetch = new Proxy(self.fetch, {
|
||||||
apply: function(target, thisArg, args) {
|
apply: function(target, thisArg, args) {
|
||||||
|
const fetchPromise = Reflect.apply(target, thisArg, args);
|
||||||
if ( reUrl.test(urlFromArg(args[0])) === false ) {
|
if ( reUrl.test(urlFromArg(args[0])) === false ) {
|
||||||
return Reflect.apply(target, thisArg, args);
|
return fetchPromise;
|
||||||
}
|
}
|
||||||
return safe.fetch(...args).then(realResponse =>
|
return fetchPromise.then(responseBefore => {
|
||||||
realResponse.text().then(text =>
|
const response = responseBefore.clone();
|
||||||
new Response(pruneFromText(text), {
|
return response.text().then(text => {
|
||||||
status: realResponse.status,
|
const responseAfter = new Response(pruneFromText(text), {
|
||||||
statusText: realResponse.statusText,
|
status: responseBefore.status,
|
||||||
headers: realResponse.headers,
|
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, {
|
self.XMLHttpRequest.prototype.open = new Proxy(self.XMLHttpRequest.prototype.open, {
|
||||||
|
|
Loading…
Reference in New Issue