Detect youtube video events with Chrome extension content script

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

    This is way late to the party, but I just recently encountered this issue myself and saw that there was never a follow up as to where to find the "HTML5 API" events.

    GabeMeister's answer is the correct solution, but using getEventListeners(document.querySelector("video")) in the console on any given YouTube video page will show you a list of events you can listen for in your script.

    As of the time of writing this, these are the events returned from the above line:

    • playing
    • pause
    • enterpictureinpicture
    • leavepictureinpicture
    • loadeddata
    • volumechange
    • timeupdate
    • play
    • durationchange
    • seeking
    • seeked
    • error
    • loadedmetadata
    • waiting
    • progress
    • focus
    • loadstart
    • ended
    • suspend
    • ratechange
    • resize

    These are separate from the iFrame API and can be listened for from a content script or through the console. Hope this helps!

提交回复
热议问题