chrome extension should pause video when youtube tab not in focus

Viewed 397

Is there a way to make it pause the video every time the tab is out of focus? In other words, video playback is possible only if the tab with it is active, and the window with this tab is also active. If the user opens another tab, in this window or in another window, the video is paused. If the user makes any application other than chrome active, the video is also paused.

1 Answers
var video = document.getElementById("youtubeVideoID"); 

Get the video element in a manner like this, listen to visibilityChange event and just play and pause the video with the HTML Dom play() methods:

video.play() video.pause()

Related