0

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.

Artjom B.
  • 61,146
  • 24
  • 125
  • 222
Roman
  • 1,652
  • 11
  • 15
  • 1
    What PhantomJS version do you have? Please register to the `onConsoleMessage`, `onError`, `onResourceError`, `onResourceTimeout` events ([Example](https://gist.github.com/artjomb/4cf43d16ce50d8674fdf)). Maybe there are errors. – Artjom B. Apr 20 '15 at 17:38
  • You right. I got `Unable to load resource (#4URL:https://xxxx.firebaseio.com/.lp?start=t&ser=38058863&cb=1&v=5)` and `Error code: 6. Description: SSL handshake failed`. – Roman Apr 20 '15 at 17:42
  • `phantomjs --ignore-ssl-errors=yes test.js` will do the trick! Thanks! – Roman Apr 20 '15 at 17:44

0 Answers0