From 1a380f09599cfb327e9cbe1321dc5add8fb38144 Mon Sep 17 00:00:00 2001 From: gorhill Date: Fri, 28 Aug 2015 10:33:58 -0400 Subject: [PATCH] this fixes https://github.com/chrisaljoudi/uBlock/issues/1528 An XML document can be a valid HTML document. Try to instanciate a HTMLDivElement to find out whether we are dealing with an actual HTML document or not. --- src/js/contentscript-end.js | 9 +++++++-- src/js/contentscript-start.js | 9 +++++++-- 2 files changed, 14 insertions(+), 4 deletions(-) diff --git a/src/js/contentscript-end.js b/src/js/contentscript-end.js index a3134fc76..9e3e1a291 100644 --- a/src/js/contentscript-end.js +++ b/src/js/contentscript-end.js @@ -33,8 +33,13 @@ // https://github.com/chrisaljoudi/uBlock/issues/464 if ( document instanceof HTMLDocument === false ) { - //console.debug('contentscript-end.js > not a HTLMDocument'); - return; + // https://github.com/chrisaljoudi/uBlock/issues/1528 + if ( + document instanceof XMLDocument === false || + document.createElement('div') instanceof HTMLDivElement === false + ) { + return; + } } // I've seen this happens on Firefox diff --git a/src/js/contentscript-start.js b/src/js/contentscript-start.js index 6a8ceff2b..21931a3e1 100644 --- a/src/js/contentscript-start.js +++ b/src/js/contentscript-start.js @@ -36,8 +36,13 @@ // https://github.com/chrisaljoudi/uBlock/issues/464 if ( document instanceof HTMLDocument === false ) { - //console.debug('contentscript-start.js > not a HTLMDocument'); - return; + // https://github.com/chrisaljoudi/uBlock/issues/1528 + if ( + document instanceof XMLDocument === false || + document.createElement('div') instanceof HTMLDivElement === false + ) { + return; + } } // This can happen