How can I call a Javascript function, defined in a script in the HTML page, from a user script?
I have a user script in Chromium loaded by dragging my.user.js to the chrome://extensions/
page. The script which Chromium sees as an extension is similar to this:
// ==UserScript==
// @match http://192.168.0.1/common_page/login.html
// ==/UserScript==
document.getElementById('loginPassword').value="a-password"
LoginFunc()
The script can do things like console.log('hello')
fine. I am trying to call a function called LoginFunc
defined on line 644 in the page HTML.
I can call LoginFunc
with the Javascript console in developer tools and it does exactly what I want. Every way I have tried to call LoginFunc
from my user script just gives LoginFunc is not defined
though.
I have tried:
setTimeout(LoginFunc(),10000)
setTimeout(function(){
if (typeof LoginFunc === "function") {
LoginFunc()
}
},10000)
setInterval(function(){
if (typeof LoginFunc === "function") {
LoginFunc()
}
},1000)
window.onload = LoginFunc
document.addEventListener('DOMContentLoaded', LoginFunc, false);