I have been looking for a means of running external script/programs against events on a web page in a browser such as “On button Click” or “On Page change”.
I am able to easily do this with the Dev Tools found in browsers. For example, in the console, I can override the default behaviour of myImage
with this:
myImage.onclick = function() {
alert('Hello World')
}
This is exactly what I need, but I have since then learnt that its ‘officially’ not possible to run scripts/programs belonging to the host machine. This seems to a be core security feature of JavaScript/Web browsers.
I am now looking for alternative means of doing the above
Is it possible to start a ‘browsing session’ at the terminal, something like ‘test mode’ or ‘debugging mode’, so that it is connected to the shell that launched it, this way I can write my code in the Dev Tools console:
myImage.onclick = function() {
logTerminal('Button has been clicked!') //possibly a custom function
}
and when the event triggers, the browser outputs a message to the terminal its connected to, Button has been clicked!
. and I am free to respond to it at the terminal.
Searching around, I came across Selenium but its feature set seems to be limited (I may be wrong) compared to what I can do at the Dev Tools console. Selenium seems to be based on polling, where the Dev Tools are event driven. I am looking for an event driven solution.
Note: I am NOT looking to deploy this as a solution for a live website, I am merely looking to, only on my local machine, “hook” into user events, like click, on sites such as the BBC/Nasa, so I can efficiently run my own tools at the right time, rather relying on polling.
Any help would be greatly appreciated!