Detect youtube video events with Chrome extension content script

前端 未结 3 580
囚心锁ツ
囚心锁ツ 2021-02-15 10:47

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条回答
  •  慢半拍i
    慢半拍i (楼主)
    2021-02-15 11:38

    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!');
    });
    

提交回复
热议问题