How can I get greasemonkey to call a function on a page after it loads

Asa Ayers picture Asa Ayers · Jan 14, 2009 · Viewed 34.1k times · Source

I have a very simple greasemonkey script that I want to call an already existing javascript function on the page. I've read the documentation and nothing seems to work

window.setTimeout(function() { 
    alert('test') // This alert works, but nothing after it does
    myFunction() // undefined
    window.myFunction() // undefined
    document.myFunction() // undefined
}, 1000);

Answer

Maiku Mori picture Maiku Mori · Jan 14, 2009

Try using: unsafeWindow.myFunction();

More details and info - http://wiki.greasespot.net/UnsafeWindow