Zombiejs empty HTML

462 views Asked by At

I'm deploying a Zombiejs application to Openshift, but Zombie seems to be unable to fetch the HTML.

I have an object (called Poker) that maintains the headless browser and does things with it. One of the methods, called init, logs in to a website and returns the "initialized" browser.

Poker.prototype.init = function (email, password, ip) {
  var self = this;
  var browser;

  // Have to use the ip that Openshift provides
  // See SO question http://goo.gl/n2TfMC
  if (ip) {
    browser = Zombie.create({
      'localAddress': ip
    });
  } else {
    browser = Zombie.create();
  }

  return new Promise(function (resolve, reject) {
    browser
      .visit('http://some.login/page')
      .then(function () {
        // Some debugging stuff :p
        console.log('body: ');
        console.log(browser.html('body'));

        // Fill in the credentials
        browser.fill('email', email);
        browser.fill('password', password);
        return browser.pressButton('Log In');
      })
      .done(function() {
        // Logged in, new page loaded
        // Check if login was successful
        var title = browser.text('title');
        console.log(title);
      });
  });
}

The console remains empty after printing body:, anden Zombie attempts to fill in the email address, I receive this error:

Possibly unhandled TypeError: Cannot use 'in' operator to search for 'compareDocumentPosition' in null
    at /var/lib/openshift/[app-id]/app-root/runtime/repo/node_modules/zombie/node_modules/jsdom/node_modules/nwmatcher/src/nwmatcher-noqsa.js:267:43
    at module.exports (/var/lib/openshift/[app-id]/app-root/runtime/repo/node_modules/zombie/node_modules/jsdom/node_modules/nwmatcher/src/nwmatcher-noqsa.js:37:7)
    at addNwmatcher (/var/lib/openshift/[app-id]/app-root/runtime/repo/node_modules/zombie/node_modules/jsdom/lib/jsdom/selectors/index.js:6:27)
    at HTMLDocument.<anonymous> (/var/lib/openshift/[app-id]/app-root/runtime/repo/node_modules/zombie/node_modules/jsdom/lib/jsdom/selectors/index.js:18:29)
    at HTMLDocument.querySelectorAll (/var/lib/openshift/[app-id]/app-root/runtime/repo/node_modules/zombie/node_modules/jsdom/lib/jsdom/level1/core.js:63:53)
    at Browser.queryAll (/var/lib/openshift/[app-id]/app-root/runtime/repo/node_modules/zombie/lib/zombie/browser.js:348:26)
    at Browser.field (/var/lib/openshift/[app-id]/app-root/runtime/repo/node_modules/zombie/lib/zombie/browser.js:591:17)
    at Browser._findOption (/var/lib/openshift/[app-id]/app-root/runtime/repo/node_modules/zombie/lib/zombie/browser.js:662:18)
    at Browser.select (/var/lib/openshift/[app-id]/app-root/runtime/repo/node_modules/zombie/lib/zombie/browser.js:692:19)
    at /var/lib/openshift/[app-id]/app-root/runtime/repo/poker.js:61:17

After I saw this, I tried to visit a different page (Google) through Zombie, but it returned empty HTML as well.

I took a look at some other StackOverflow questions about the compareDocumentPosition error, but I think the one I'm having is related to deployment on Openshift rather than an issue with the HTML of the page I'm visiting.

I'm using Node.js v0.10.25 and Zombie v2.2.1.

2

There are 2 answers

2
user2048239 On

Are you sure the variable "browser" you are trying to work with is an Object, that error can occur if the variable is a string.

1
Julien Bérubé On

Can it be a CORS problem? .login is not a valid TLD and rules vary per TLD.