From d82a7e1ece5a504e5f1790f455e3e39f5618394c Mon Sep 17 00:00:00 2001 From: gorhill Date: Mon, 15 Aug 2016 07:52:50 -0400 Subject: [PATCH] fix #1897 --- src/js/scriptlets/element-picker.js | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/src/js/scriptlets/element-picker.js b/src/js/scriptlets/element-picker.js index 5ede51dac..2968a9756 100644 --- a/src/js/scriptlets/element-picker.js +++ b/src/js/scriptlets/element-picker.js @@ -327,11 +327,15 @@ var unpreview = function() { /******************************************************************************/ +// https://github.com/gorhill/uBlock/issues/1897 +// Ignore `data:` URI, they can't be handled by an HTTP observer. + var backgroundImageURLFromElement = function(elem) { - var style = window.getComputedStyle(elem); - var bgImg = style.backgroundImage || ''; - var matches = /^url\((["']?)([^"']+)\1\)$/.exec(bgImg); - return matches !== null && matches.length === 3 ? matches[2] : ''; + var style = window.getComputedStyle(elem), + bgImg = style.backgroundImage || '', + matches = /^url\((["']?)([^"']+)\1\)$/.exec(bgImg), + url = matches !== null && matches.length === 3 ? matches[2] : ''; + return url.lastIndexOf('data:', 0) === -1 ? url.slice(0, 1024) : ''; }; /******************************************************************************/