title: Trigger an event from a youtube player state on youtube.com
body: <p>I'm trying to trigger an event in an extension when a video ends on youtube.com. </p>
  
  <p>I couldn't find any examples from other extensions.</p>
  
  <p>What I tried so far:</p>
  
  <p>EDIT: I injected the script just like here: <a href="https://stackoverflow.com/a/9310273/4279201">https://stackoverflow.com/a/9310273/4279201</a></p>
  
  <p>Now with the injection, the <code>alert('test')</code> does show up so the injection works up to that point. But then nothing happens, any ideas why?</p>
  
  <pre><code>//script.js file
          alert('test');
          function onPlayerStateChange(event) {        
              if(event.data === YT.PlayerState.ENDED) {          
                  alert('done');
              }
          }
  </code></pre>
  
  <p>Or:</p>
  
  <pre><code>//script.js file
    alert('test');
    var player;
    function onYouTubeIframeAPIReady() {
      player = new YT.Player( 'player', {
        events: { 'onStateChange': onPlayerStateChange }
      });
    }
    function onPlayerStateChange(event) {
       if(event.data === YT.PlayerState.ENDED) {          
           alert('done');
          }
    }
  </code></pre>
  
  <p>The event constant is from: <a href="https://developers.google.com/youtube/js_api_reference?csw=1#Events" rel="nofollow noreferrer">https://developers.google.com/youtube/js_api_reference?csw=1#Events</a></p>
  
  <p>My manifest file: <a href="http://chopapp.com/#j89brn5f" rel="nofollow noreferrer">http://chopapp.com/#j89brn5f</a>, <code>bk.js</code> is empty, <code>cnt.js</code> is just like in the script injection link. <code>script.js</code> is above.</p>