Why doesn't Phantom.js evaluate work with my Backbone app?

page.open(My_url, function(status) {
                        page.evaluate(function() { 
                            var html = document.documentElement.outerHTML;
                            return html;
                        }, function(result){
                            res.send(result);
                        });
                    });

I have a Backbone app. "My_url" points to that backbone page.

When I run this code, the outerHTML does not include the rendered views. It just has the basic css/scripts/container holders.

It's like the Backbone app did not run at all. How do I make evaluate() return the fully rendered Backbone app (after all the ajax calls and stuff)?

After all, that's the point of Phantom.js

It isn't always sufficient to evaluate a page immediately after it loads. Sometimes, due to the way the JavaScript is written on the page, you will have to wait and allow the page's JavaScript to execute. To this end I suggest you try and add a wait before performing your evaluation. e.g.

function ( status ) {
  if ( status === 'fail' ) {
    phantom.exit( 1 );
    return; // essential, if you don't, below will be executed
  }

  window.setTimeout(
    function () {
      var result = page.evaluate(
        function () {
          var html = document.documentElement.outerHTML;
          return html;
        }
      );
      res.send( result );
    },
    1000 // wait 1,000ms (1s)
  );
}

If you discover it IS necessary to wait then you might want to wait FOR something. To this end look for a waitFor or similar function on the Internet that will allow your script to continuously poll until a particular DOM element appears.