I am not able to connect to Firebase when the page is loaded in PhantomJS. Connecting in a browser works fine.
index.html
<!DOCTYPE html>
<html>
  <body>
    <div id="connection"></diV>
  </body>
  <script src="https://cdn.firebase.com/js/client/2.2.2/firebase.js"></script>
  <script src="index.js"></script>
</html>
index.js
var output = document.getElementById('connection');
var ref = new Firebase('https://xxxx.firebaseio.com/');
ref.child('.info/connected').on('value', function(connectedSnap) {
    if (connectedSnap.val() === true) {
        output.textContent = 'connected';
    } else {
        output.textContent = 'disconnected';
    }
});
When I run a http server and open localhost:8080 in a browser I can see the connection status switch from disconnected to connected.
test.js
var page = require('webpage').create();
page.open('http://localhost:8080', function() {
    setInterval(function() {
        var connectionStatus = page.evaluate(function() {
            return document.getElementById('connection').textContent;
        });
        console.log('Firebase status:', connectionStatus);
    }, 2000);
});
When I do the same in PhantomJS (running phantomjs test.js) the connection status never gets connected. I can't see any error messages (even if I log errors) so I have no clue what is going wrong. Any idea? Thank You.
 
    