Hopi Hopi - 1 month ago 21
Javascript Question

Is it possible to run setTimeout inside a iframe?

I am trying to start an embedded videojs video using Greasemonkey. The video is running in a iframe and I managed to start the video in chrome with Tampermonkey but in Firefox the video starts loading and stops a sec later. I guess my following script starts too soon after reloading the page so I tried to delay the start with setTimeout but the code won't start. So my question is it possible to use setTimeout inside an iframe?

// ==UserScript==
// @name Autoplay
// @namespace openload
// @include https://openload.co/embed/*
// @version 1.0.0
// @run-at document-idle
// ==/UserScript==

window.setTimeout(play, 5000);
function play()
{
console.log("Start");
document.querySelector('#videooverlay').click();
videojs.getPlayers()['olvideo'].player_.play();
console.log("End");
}


I use @include https://openload.co/embed/* to run the script inside the iframe otherwise I can't use the command .play().
If I open the iframeurl manually and use the commands over the FF console it works perfectly.

Answer

Maybe try something like this

window.addEventListener ("load", playerstart, false);

function playerstart () {

}