From 9156973f76f02def8bb2c95388c5afcccf2b1f26 Mon Sep 17 00:00:00 2001 From: Julian Poyourow Date: Wed, 4 Dec 2019 21:48:31 -0800 Subject: [PATCH] WE: Add some filtering to remove bad images --- WebExtension/src/inject/inject.js | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/WebExtension/src/inject/inject.js b/WebExtension/src/inject/inject.js index 845157465..cdaad99a7 100644 --- a/WebExtension/src/inject/inject.js +++ b/WebExtension/src/inject/inject.js @@ -53,7 +53,13 @@ if (window[extensionContainerId]) { return (exactMatches.length > 0 ? exactMatches : fuzzyMatches) .reduce((acc, element) => [...acc, ...getImgElementsWithin(element)], []) - .filter(element => isImg(element) && element.src) + .filter(element => + isImg(element) && + element.src && + element.complete && // Filter images that haven't completely loaded + element.naturalWidth > 0 && // Filter images that haven't loaded correctly + element.naturalHeight > 0 + ) .reduce((max, element) => (element.offsetHeight * element.offsetWidth) > (max ? (max.offsetHeight * max.offsetWidth) : 0) ? element : max, null) }