Improve xml-prune scriptlet

Related feedback:
- https://github.com/uBlockOrigin/uBlock-discussions/discussions/792#discussioncomment-6536598
This commit is contained in:
Raymond Hill 2023-07-25 09:05:39 -04:00
parent ceb7e0c10b
commit 334a7440f3
No known key found for this signature in database
GPG key ID: 25E1490B761470C2

View file

@ -2397,7 +2397,11 @@ function xmlPrune(
thisArg.addEventListener('readystatechange', function() {
if ( thisArg.readyState !== 4 ) { return; }
const type = thisArg.responseType;
if ( type === 'text' ) {
if ( type === 'document' || thisArg.responseXML instanceof XMLDocument ) {
pruneFromDoc(thisArg.responseXML);
return;
}
if ( type === 'text' || typeof thisArg.responseText === 'string' ) {
const textin = thisArg.responseText;
const textout = pruneFromText(textin);
if ( textout === textin ) { return; }
@ -2405,10 +2409,6 @@ function xmlPrune(
Object.defineProperty(thisArg, 'responseText', { value: textout });
return;
}
if ( type === 'document' ) {
pruneFromDoc(thisArg.response);
return;
}
});
return Reflect.apply(target, thisArg, args);
}