@@ -30,7 +30,8 @@ chrome.runtime.onInstalled.addListener(details => {
3030
3131function onMute ( tabId ) {
3232 mutedTabs . add ( tabId ) ;
33- if ( ! hasProperty ( options , 'muteonpause' ) ) media . delete ( tabId ) ;
33+ // Pause hidden muted tabs.
34+ pause ( tabId , true ) ;
3435 onPause ( tabId ) ;
3536}
3637
@@ -42,13 +43,16 @@ chrome.runtime.onMessage.addListener(async (message, sender) => {
4243 switch ( message . type ) {
4344 case 'hidden' :
4445 if ( mutedTabs . has ( sender . tab . id ) ) {
46+ if ( hasProperty ( options , 'muteonpause' ) ) {
47+ media . add ( sender . tab . id ) ;
48+ chrome . tabs . update ( sender . tab . id , { "muted" : true } ) ;
49+ }
4550 // Pause hidden muted tabs.
4651 pause ( sender . tab . id ) ;
4752 }
4853 break
4954 case 'play' :
5055 if ( sender . tab . mutedInfo . muted ) {
51- if ( hasProperty ( options , 'muteonpause' ) ) media . add ( sender . tab . id ) ;
5256 onMute ( sender . tab . id ) ;
5357 } else {
5458 media . add ( sender . tab . id ) ;
@@ -58,6 +62,7 @@ chrome.runtime.onMessage.addListener(async (message, sender) => {
5862 case 'playMuted' :
5963 let playing1 = await isPlaying ( sender . tab . id ) ;
6064 if ( playing1 ) break
65+ media . delete ( sender . tab . id ) ;
6166 onMute ( sender . tab . id ) ;
6267 break
6368 case 'pause' :
@@ -232,7 +237,6 @@ function pause(id, checkHidden) {
232237 return
233238 }
234239 if ( otherTabs . has ( id ) ) return
235- if ( hasProperty ( options , 'muteonpause' ) ) chrome . tabs . update ( id , { "muted" : true } ) ;
236240 if ( checkHidden ) {
237241 send ( id , 'hidden' ) ;
238242 } else {
@@ -297,12 +301,10 @@ chrome.tabs.onUpdated.addListener((tabId, changeInfo, tab) => {
297301 }
298302 if ( hasProperty ( changeInfo , 'mutedInfo' ) ) {
299303 if ( changeInfo . mutedInfo . muted && media . has ( tabId ) ) {
300- // Pause hidden muted tabs.
301- pause ( tabId , true ) ;
302304 onMute ( tabId ) ;
303305 }
304306 // If tab gets unmuted resume it.
305- else if ( ! changeInfo . mutedInfo . muted && mutedTabs . has ( tabId ) ) {
307+ else if ( ! changeInfo . mutedInfo . muted && media . has ( tabId ) ) {
306308 mediaPlaying = tabId ;
307309 play ( tabId , true ) ;
308310 }
@@ -350,7 +352,7 @@ function send(id, message, force, body = "") {
350352function isPlaying ( id ) {
351353 return new Promise ( resolve => {
352354 if ( otherTabs . has ( id ) ) return true
353- chrome . tabs . sendMessage ( id , 'isplaying' , r => {
355+ chrome . tabs . sendMessage ( id , { type : 'isplaying' } , r => {
354356 var lastError = chrome . runtime . lastError ; // lgtm [js/unused-local-variable]
355357 resolve ( r === 'true' ) ;
356358 } ) ;
0 commit comments