Search code examples
javascriptvideoyoutube

How to play and pause a Youtube video in the console?


Go to an url such as:

https://www.youtube.com/embed/zvCBSSwgtg4

and open the chrome console. I want to know what javascript command will play the youtube video and what javascript command will pause the youtube video.

I've tried using the profiler and inspector to find these commands but they are too well hidden. If someone is really good at javascript debugging, this would be a big help. Thanks!

Yes, I know youtube has API for iframes, but my use case is different.


Solution

  • Have you tried triggering a click on the actual play/pause button?

    document.getElementsByClassName('ytp-play-button')[0].click();