Improve handling of srcset-based images in element picker

Related issue:
- https://github.com/uBlockOrigin/uBlock-issues/issues/517
This commit is contained in:
Raymond Hill 2019-04-14 17:37:48 -04:00
parent b73480b4c5
commit 7652808806
No known key found for this signature in database
GPG key ID: 25E1490B761470C2

View file

@ -342,7 +342,7 @@ const resourceURLFromElement = function(elem) {
} }
if ( typeof elem.srcset === 'string' && elem.srcset !== '' ) { if ( typeof elem.srcset === 'string' && elem.srcset !== '' ) {
const ss = []; const ss = [];
for ( let s of elem.srcset.split(/\s*,\s+/) ) { for ( let s of elem.srcset.split(',') ) {
const pos = s.indexOf(' '); const pos = s.indexOf(' ');
if ( pos !== -1 ) { s = s.slice(0, pos); } if ( pos !== -1 ) { s = s.slice(0, pos); }
const parsedURL = new URL(s, document.baseURI); const parsedURL = new URL(s, document.baseURI);
@ -471,10 +471,6 @@ const netFilter1stSources = {
'video': 'src' 'video': 'src'
}; };
const netFilter2ndSources = {
'img': 'srcset'
};
const filterTypes = { const filterTypes = {
'audio': 'media', 'audio': 'media',
'embed': 'object', 'embed': 'object',
@ -750,8 +746,13 @@ const filterToDOMInterface = (function() {
let srcProp = netFilter1stSources[elem.localName]; let srcProp = netFilter1stSources[elem.localName];
let src = elem[srcProp]; let src = elem[srcProp];
if ( typeof src !== 'string' || src.length === 0 ) { if ( typeof src !== 'string' || src.length === 0 ) {
srcProp = netFilter2ndSources[elem.localName]; if (
src = elem[srcProp]; typeof elem.srcset === 'string' &&
elem.srcset !== '' &&
typeof elem.currentSrc === 'string'
) {
src = elem.currentSrc;
}
} }
if ( src && reFilter.test(src) ) { if ( src && reFilter.test(src) ) {
out.push({ out.push({