From 81fadf836f305a9065bbebe21ca38afb7b12c8ee Mon Sep 17 00:00:00 2001 From: Raymond Hill Date: Tue, 27 Apr 2021 08:59:59 -0400 Subject: [PATCH] Stop autoplay for unset media source with no-large-media-elements Related feedback: - https://www.reddit.com/r/uBlockOrigin/comments/mxgpmc/ --- src/js/scriptlets/load-large-media-interactive.js | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/src/js/scriptlets/load-large-media-interactive.js b/src/js/scriptlets/load-large-media-interactive.js index 2af43502b..d5ed30847 100644 --- a/src/js/scriptlets/load-large-media-interactive.js +++ b/src/js/scriptlets/load-large-media-interactive.js @@ -213,6 +213,19 @@ const onLoadedData = function(ev) { media.pause(); }; +// https://www.reddit.com/r/uBlockOrigin/comments/mxgpmc/ +// Support cases where the media source is not yet set. +for ( const media of document.querySelectorAll('audio,video') ) { + const src = media.src; + if ( + (typeof src === 'string') && + (src === '' || src.startsWith('blob:')) + ) { + media.autoplay = false; + media.pause(); + } +} + document.addEventListener('loadeddata', onLoadedData); /******************************************************************************/