I am trying to run a function every time the player state changes but onStateChange is not firing when I use the following code in my extension.
function onPlayerStateChange( newState ) {
console.log( "New state: " + newState );
}
player = document.getElementById( "movie_player" );
player.addEventListener( "onStateChange", "onPlayerStateChange" );
It runs fine when I run it through the chrome javascript console but for some reason I have not been able to get it to work with my extension.
This is the relevant part of the manifest.json:
"content_scripts": [ {
"matches": [ "*://*.youtube.com/watch*" ],
"js": [ "jquery.js", "page.js" ]
} ],
And this is a part of page.js:
function onPlayerStateChange( newState ) {
console.log( "New state: " + newState );
}
player = document.getElementById( "movie_player" );
player.addEventListener( "onStateChange", "onPlayerStateChange" );