Question

I'm looking for a way to fire an JavaScript event in a remote web page without opening it on browser.

I mean, let-me explain my situation: What I do now is, I have two scripts running on GreaseMonkey at specific web pages. Script A on page A, Script B on page B.

The script A keeps sending xmlHttpRequests to page B, it gets the data, process in a reg-exp, and make some comparisons. When my condition on Script A is satisfied, I send an window.open to open page B.

On page B, I have the script B running, the script B check the content of page B again, see if the SAME condition of script A is satisfied, making a double check, and then fire the click events that I need.

The problem is, too slow. I need to optimize it. Is too slow to open the Page B and load it's contents, like lot's of images, backgrounds, css styles, etc. It takes some seconds to load the page, between 5 to 10 seconds, to be precise. I need it to be under 1 or 2 seconds.

Is there a way to fire JavaScript events on page B, without loading the whole content of page B?

Thank you.

Was it helpful?

Solution

Not reliably.

You could set up a node instance to request the page, and run server-side JavaScript against the http response, but that wouldn't be anything like running a script in a browser window that can interact with the scripts that the page runs, and the assets it pulls in from other URLs.

To fire an event on a page it would have to be loaded into a browser. You could speed things up with Phantom or another headless browser though.

I'd recommend the latter if you want performance and quality over greasemonkey any day. It's a little more complex, but if this is an ongoing comparison automating it into the background and away from a rendering browser seems best.

OTHER TIPS

my solution may not be perfect, but you could do the next (as you ar on GreaseMonkey)

1- XMLHTTPrequest page B

2- make the comparison

3- if satisfied, put the innerHTML you got from the first XMLHTTPrequest into a new div/iframe you create and make invisible

4- there you can run the click event into that div/iframe

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top