Add support to report/filter SVG image elements

Related issue:
- https://github.com/uBlockOrigin/uBlock-issues/issues/2260
This commit is contained in:
Raymond Hill 2022-09-11 12:20:01 -04:00
parent 3e26a1ead8
commit 887a87d9ca
No known key found for this signature in database
GPG Key ID: 25E1490B761470C2
1 changed files with 13 additions and 3 deletions

View File

@ -221,7 +221,8 @@ const backgroundImageURLFromElement = function(elem) {
// https://github.com/gorhill/uBlock/issues/1725#issuecomment-226479197
// Limit returned string to 1024 characters.
// Also, return only URLs which will be seen by an HTTP observer.
// https://github.com/uBlockOrigin/uBlock-issues/issues/2260
// Maybe get to the actual URL indirectly.
const resourceURLsFromElement = function(elem) {
const urls = [];
const tagName = elem.localName;
@ -231,7 +232,10 @@ const resourceURLsFromElement = function(elem) {
if ( url !== '' ) { urls.push(url); }
return urls;
}
const s = elem[prop];
let s = elem[prop];
if ( s instanceof SVGAnimatedString ) {
s = s.baseVal;
}
if ( typeof s === 'string' && /^https?:\/\//.test(s) ) {
urls.push(trimFragmentFromURL(s.slice(0, 1024)));
}
@ -376,6 +380,7 @@ const netFilter1stSources = {
'embed': 'src',
'iframe': 'src',
'img': 'src',
'image': 'href',
'object': 'data',
'source': 'src',
'video': 'src'
@ -671,12 +676,17 @@ const filterToDOMInterface = (( ) => {
}
// Lookup by tag names.
// https://github.com/uBlockOrigin/uBlock-issues/issues/2260
// Maybe get to the actual URL indirectly.
const elems = document.querySelectorAll(
Object.keys(netFilter1stSources).join()
);
for ( const elem of elems ) {
const srcProp = netFilter1stSources[elem.localName];
const src = elem[srcProp];
let src = elem[srcProp];
if ( src instanceof SVGAnimatedString ) {
src = src.baseVal;
}
if (
typeof src === 'string' &&
reFilter.test(src) ||