How to stop music when a browser is minimized or a tab is changed?

I’ve tried this but it doesnt work :

“// ---------------------------
// Add the code - Check focus game (pause/play music)
// Adding a page visibility state handler
document.addEventListener (‘visibilitychange’, function () {
// If the page is hidden
if (document.visibilityState == ‘hidden’)
// Pause music playing on channel 1
// In all other cases, we play music on 1 channel
// ---------------------------”

Any solution with a help of events or javascript?

I believe we have a window focus condition, but it might not be compatible with browsers.

Hi guest, I didn’t understand the stuff you posted, but have you tried the solution mentioned in this thread?


Thanks a lot ! You are my savior. An extension “PauseFocusLost” does exactly what i need. I didn’t even notice it before.

1 Like