From aec0bd39e3a7dc924885c79ccef80f177345c405 Mon Sep 17 00:00:00 2001 From: Raymond Hill Date: Thu, 26 Sep 2024 13:27:06 -0400 Subject: [PATCH] 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. --- .../load-large-media-interactive.js | 24 +++++++++---------- 1 file changed, 12 insertions(+), 12 deletions(-) diff --git a/src/js/scriptlets/load-large-media-interactive.js b/src/js/scriptlets/load-large-media-interactive.js index 57198e4b2..4887616d9 100644 --- a/src/js/scriptlets/load-large-media-interactive.js +++ b/src/js/scriptlets/load-large-media-interactive.js @@ -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); } };