From d996a1351b541d2c6b8103aacea40ccdfb2b0dfc Mon Sep 17 00:00:00 2001 From: Russell Ballestrini Date: Wed, 2 Jul 2025 07:36:04 -0400 Subject: [PATCH] enhance(tts): improve auto-play handling with browser policy support - Add proper error handling for browser auto-play restrictions - Set button text correctly based on auto-play success/failure - Add console logging for debugging auto-play behavior - Gracefully handle cases where auto-play is blocked --- src/ui.js | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/src/ui.js b/src/ui.js index f477093..81da52f 100644 --- a/src/ui.js +++ b/src/ui.js @@ -2290,11 +2290,18 @@ export function openTTSModal() { const result = await speakText(currentText, selectedVoice, selectedSpeed); ttsAudio = result.audio; ttsBlob = result.blob; - playButton.textContent = "Pause Text"; playButton.disabled = false; - // Auto-play the audio - ttsAudio.play(); + // Auto-play the audio (handle browser auto-play policies) + try { + await ttsAudio.play(); + console.log("TTS audio auto-playing"); + playButton.textContent = "Pause Text"; + } catch (error) { + console.log("Auto-play prevented by browser policy:", error.message); + playButton.textContent = "Play Text"; + // Don't throw error, just log it - user can manually click play + } // Add download button if not exists let downloadButton = article.querySelector(".download-btn");