From 334a7440f37fbc9f18a2ea020919e80b4dc1220d Mon Sep 17 00:00:00 2001 From: Raymond Hill Date: Tue, 25 Jul 2023 09:05:39 -0400 Subject: [PATCH] Improve `xml-prune` scriptlet Related feedback: - https://github.com/uBlockOrigin/uBlock-discussions/discussions/792#discussioncomment-6536598 --- assets/resources/scriptlets.js | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/assets/resources/scriptlets.js b/assets/resources/scriptlets.js index 3f411151a..bd3760358 100644 --- a/assets/resources/scriptlets.js +++ b/assets/resources/scriptlets.js @@ -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); }