Detect youtube video events with Chrome extension content script

前端 未结 3 782
终归单人心
终归单人心 2021-02-15 10:55

I\'m writing a Chrome extension and I want to detect when a video starts/ends while a user is on youtube.com watching videos. The difference between my situation and other tutor

3条回答
  •  广开言路
    2021-02-15 11:48

    I found a similar questions here, the answers are great (HTML5 is amazing!!) How to play and pause a Youtube video in the console?

    for instance, you can use these to play/pause the video (on youtube.com, without youtube iframe on an external website)

    document.getElementsByTagName('video')[0].play()
    document.getElementsByTagName('video')[0].pause()
    

    there are more functions allowing you to track video length, current play time and more.

    P.S: I was having this same question for over a day and it's surprisingly to hard to find the right answer/guide to this! but hope this helps

提交回复
热议问题