I'm writing a Chrome extension to alter the functionality of YouTube. I have code injected onto the page, and I'm trying to trigger fullscreen of the video in certain circumstances.
I've done everything I can think of, but to no avail.
Double-clicking the video:
$('video').click();
setTimeout(function() {
$('video').click();
}, 40);
But this way doesn't work. I'm not sure why, but I think Youtube expects a 'real' click or something?
Simulating the 'f' keypress:
var event = document.createEvent("UIEvents");
event.initUIEvent("keypress", true, true, window, 1);
event.keyCode = 70;
And dozens of variations of the above, none seem to work. Think it might be a Webkit thing.
Linking to a video in the format: https://www.youtube.com/v/<vid-id>
. But this won't suit my purposes because I need to be able to call it again after page load.
Anyone any ideas on how to make Youtube full screen after page load via Javascript?