Detect youtube video events with Chrome extension content script

前端 未结 3 777
终归单人心
终归单人心 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:41

    Shortly after I posted this question I found out an answer. Not using the youtube iframe api, but rather the html5 api. I modified the content script to the following to print a message when the video ends and it works fine.

    var vid = $('video').get(0);
    
    vid.addEventListener('ended', function(e) {
        console.log('The video ended!');
    });
    

提交回复
热议问题