Fix images not properly downloading on click

Related feedback:
https://github.com/uBlockOrigin/uBlock-issues/issues/1670#issuecomment-2372048056

The issue affected images supporting `srcset` attribute without
the presence of `src` attribute. This commit takes add fallback
onto `srcset` attribute when the `src` attribute is not present.
This commit is contained in:
Raymond Hill 2024-09-26 13:27:06 -04:00
parent 03df1a40d8
commit aec0bd39e3
No known key found for this signature in database
GPG Key ID: 25E1490B761470C2
1 changed files with 12 additions and 12 deletions

View File

@ -19,10 +19,6 @@
Home: https://github.com/gorhill/uBlock
*/
'use strict';
/******************************************************************************/
(( ) => {
/******************************************************************************/
@ -132,15 +128,12 @@ if ( vAPI.largeMediaElementStyleSheet === undefined ) {
const loadMedia = async function(elem) {
const src = elem.getAttribute('src') || '';
if ( src === '' ) { return; }
elem.removeAttribute('src');
await vAPI.messaging.send('scriptlets', {
what: 'temporarilyAllowLargeMediaElement',
});
if ( src !== '' ) {
elem.setAttribute('src', src);
}
elem.setAttribute('src', src);
elem.load();
};
@ -148,14 +141,21 @@ const loadMedia = async function(elem) {
const loadImage = async function(elem) {
const src = elem.getAttribute('src') || '';
elem.removeAttribute('src');
const srcset = src === '' && elem.getAttribute('srcset') || '';
if ( src === '' && srcset === '' ) { return; }
if ( src !== '' ) {
elem.removeAttribute('src');
}
if ( srcset !== '' ) {
elem.removeAttribute('srcset');
}
await vAPI.messaging.send('scriptlets', {
what: 'temporarilyAllowLargeMediaElement',
});
if ( src !== '' ) {
elem.setAttribute('src', src);
} else if ( srcset !== '' ) {
elem.setAttribute('srcset', srcset);
}
};