alexscheelmeyer / node-phantom

bridge to PhantomJS from Node.js
317 stars 117 forks source link

Problems with event listener #72

Open matthewcheok opened 11 years ago

matthewcheok commented 11 years ago

I'm trying to grab the html when AJAX operations are complete with some client javascript like this:

var evt = document.createEvent('Event');
evt.initEvent('__htmlReady__', true, true);
document.dispatchEvent(evt);

I'm listening for events like this:

page.onCallback = function() {
  page.get('content', function(err, html) {
    ph.exit();
    console.log(html);
  });
};

page.onInitialized = function() {
  page.evaluate(function() {
    document.addEventListener('__htmlReady__', function() {
      window.callPhantom();
    }, false);
    setTimeout(function() {
      window.callPhantom();
    }, 10000);
  });
};

But the event never triggers, only the timeout triggers. This issue doesn't happen when I run phantomjs from the command line.

Any ideas?

alexscheelmeyer commented 11 years ago

Hmm, hard to tell without an example setup where I can try to reproduce it - it could be many things I guess.