Hi,
I’m trying to load a YouTube video then use two javascript commands to act on the page:
-
Force the video fullscreen.
-
Play the video.
Here is the code I’m using now:
var url = "https://www.youtube.com/embed/Gz-jBbuqHZg?start=100"
var type = "video";
var view = new WebView;
let jsCode = `
document.getElementsByClassName('ytp-play-button')[0].click();
document.querySelector("video").webkitEnterFullScreen();
`
// load the url into the webview
view.loadURL(url);
console.log("loading the page");
// wait for the page to load
view.waitForLoad();
console.log("page loaded");
// show the page fullscreen
view.present(true);
console.log("showing the page");
// maximize the video, hide the chrome and play the video
view.evaluateJavaScript(jsCode);
Things go as planned, but the JS code does not do anything. If I use these same commands as bookmarklets they work just fine. I know this is a stupid mistake. Please point out the error of my ways.