0

I need to open multiple windows/tabs of firefox using Node. Now, when i use a spawn() call:

var spawn = require('child_process').spawn;
ff = spawn('firefox', ['www.stackoverflow.com', '-new-tab']);

If i use two (or more) calls right after the other, firefox claims there's a page that is not responding, and will not open another window.
That can be solved using some implementation of sleep() - which is bad practice because there's no way of knowing the actual loading time.
This is why i'm looking for an event that is fired when a firefox window/tab is considered "not busy"- I have searched in the ChildProcess class documentation and didn't see any event of such.
Since the page i'm loading connects to a Node http server, and uses socket.io, i was thinking of a workaround: when the page finishes loading, i'll use socket.io to notify the server that the window is ready, and then be able to open a new window- but that just seems wrong.

Community
  • 1
  • 1
bks
  • 1,886
  • 1
  • 24
  • 43

1 Answers1

0

I eventually went with the socket.io workaround; In the client side I used jQuery in order to know when the page was fully loaded and then sent a "page loaded" message via socket.io:

//client side:
jQuery(function($)
{
    socket = io.connect();
    socket.emit('page loaded', {'someKey': 8);
}

If someone have a better way, i'de be glad to hear

bks
  • 1,886
  • 1
  • 24
  • 43