Skip to content

Feat/force autoplay on refresh - #4259

Open
MoriMomo wants to merge 6 commits into
code-charity:masterfrom
MoriMomo:feat/force-autoplay-on-refresh
Open

Feat/force autoplay on refresh#4259
MoriMomo wants to merge 6 commits into
code-charity:masterfrom
MoriMomo:feat/force-autoplay-on-refresh

Conversation

@MoriMomo

@MoriMomo MoriMomo commented Aug 4, 2026

Copy link
Copy Markdown
Contributor

Summary of Changes

  • Settings Menu: Added the force_autoplay_on_refresh switch in the player options menu.
  • Localization: Added the forceAutoplayOnRefresh key ("Force autoplay / auto-resume on page reload") in _locales/en/messages.json.
  • Player Autoplay Handling: Added ImprovedTube.forceAutoplayOnRefresh in js&css/web-accessible/www.youtube.com/player.js. If browser autoplay policies block unmuted playback (NotAllowedError), it falls back to muted autoplay.
  • Initialization: Wired forceAutoplayOnRefresh in init.js and initPlayer in functions.js.
  • Unit Tests: Added test suite tests/unit/force-autoplay-on-refresh.test.js (all 22 test suites / 97 tests passing).

Closes #4239

Copilot AI review requested due to automatic review settings August 4, 2026 02:03

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Adds an opt-in “Force autoplay / auto-resume on page reload” player setting and wires it into initialization so the extension attempts to resume playback after refresh/navigation, with a muted fallback path for autoplay-policy blocking. The PR also includes Shorts autoplay/loop behavior changes and Firefox keyboard shortcut handling updates.

Changes:

  • Add force_autoplay_on_refresh setting (menu + locale) and implement ImprovedTube.forceAutoplayOnRefresh() with init wiring.
  • Update Shorts playback behavior (stop autoloop + click-next on ended) and add unit tests around Shorts + new force-autoplay behavior.
  • Adjust keyboard shortcut event listener registration for Firefox compatibility and add a Firefox shortcuts test guide.

Reviewed changes

Copilot reviewed 9 out of 9 changed files in this pull request and generated 8 comments.

Show a summary per file
File Description
tests/unit/shorts-autoplay.test.js Adds unit coverage for Shorts autoloop stopping and Shorts “next” behavior on ended.
tests/unit/force-autoplay-on-refresh.test.js Adds unit coverage asserting the new setting exists, is localized, is wired, and attempts playback with a muted fallback.
TEST_FIREFOX_SHORTCUTS.md Adds a manual test guide for Firefox shortcut focus behavior.
menu/skeleton-parts/player.js Adds the force_autoplay_on_refresh switch to the Player settings UI.
js&css/web-accessible/www.youtube.com/shortcuts.js Adds document-level key listeners and adjusts “ignore typing targets” logic.
js&css/web-accessible/www.youtube.com/player.js Implements ImprovedTube.forceAutoplayOnRefresh() and autoplay-policy handling.
js&css/web-accessible/init.js Calls forceAutoplayOnRefresh() on init/navigation and changes Shorts autoloop gating; comments out YouTubeExperiments() on SPA navigation.
js&css/web-accessible/functions.js Refactors Shorts autoloop stopping, adds Shorts “next” click on ended, and calls forceAutoplayOnRefresh() during initPlayer().
_locales/en/messages.json Adds the forceAutoplayOnRefresh locale message.
Suppressed comments (2)

js&css/web-accessible/init.js:286

  • Same default-enabling issue here: up_next_autoplay !== false makes Shorts behavior change even when the setting is unset. Use an explicit === true check (or isset-based check) to avoid enabling by default.
		ImprovedTube.redirectShortsToWatch();
		if (ImprovedTube.storage.prevent_shorts_autoloop || ImprovedTube.storage.up_next_autoplay !== false) {
			ImprovedTube.stop_shorts_autoloop();
		}

js&css/web-accessible/functions.js:605

  • ImprovedTube.storage.up_next_autoplay !== false enables Shorts “next video” clicks by default when the setting is unset. If the intention is opt-in (or at least consistent with upNextAutoplay()’s isset behavior), this should check for === true instead.
	if (document.documentElement.dataset.pageType === 'shorts' && ImprovedTube.storage.up_next_autoplay !== false) {
		const nextButton = document.querySelector('#navigation-button-down button') || 
		                   document.querySelector('button[aria-label="Next video"]');
		if (nextButton) {
			nextButton.click();
		}
	}

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment on lines 49 to +53
window.addEventListener(name, handler, {passive: false, capture: true});
// Firefox compatibility: also listen on document for keyboard events
if (name === 'keydown' || name === 'keyup') {
document.addEventListener(name, handler, {passive: false, capture: true});
}
Comment on lines 82 to +86
window.removeEventListener(name, handler, {passive: false, capture: true});
// Firefox compatibility: also remove from document
if (name === 'keydown' || name === 'keyup') {
document.removeEventListener(name, handler, {passive: false, capture: true});
}
Comment on lines +128 to +129
// fallback check for activeElement (for nested elements)
if (document.activeElement && ImprovedTube.input.ignoreElements.includes(document.activeElement.tagName) && document.activeElement.isContentEditable) return;
Comment on lines +3094 to +3104
if (player && typeof player.playVideo === 'function') {
try {
playPromise = player.playVideo();
} catch (e) {
if (video && typeof video.play === 'function') {
playPromise = video.play();
}
}
} else if (video && typeof video.play === 'function') {
playPromise = video.play();
}
Comment on lines +3107 to +3109
playPromise.catch(function (error) {
if (player && typeof player.mute === 'function') {
try { player.mute(); } catch (e) {}
Comment on lines 253 to 255
ImprovedTube.pageType();
ImprovedTube.YouTubeExperiments();
// ImprovedTube.YouTubeExperiments();
ImprovedTube.commentsSidebar();
Comment on lines +208 to 210
if (ImprovedTube.storage.prevent_shorts_autoloop || ImprovedTube.storage.up_next_autoplay !== false) {
ImprovedTube.stop_shorts_autoloop();
}
Comment on lines +457 to +461
if (document.documentElement.dataset.pageType === 'shorts') {
if (ImprovedTube.storage.prevent_shorts_autoloop || ImprovedTube.storage.up_next_autoplay !== false) {
ImprovedTube.stop_shorts_autoloop(this);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

💡[Feature Request] Option to force resume/autoplay video after page refresh

2 participants