0

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.

apparatix
  • 1,492
  • 7
  • 22
  • 37
  • perhaps `.then` does not wait for the page to completely load. See [this answer](http://stackoverflow.com/questions/19101258/why-does-the-zombie-js-browser-return-empty-html-when-using-bootstrap) for a possible workaround – yuvi Nov 26 '14 at 15:56
  • I tried using `.wait()`, the body is still empty – apparatix Nov 26 '14 at 16:08
  • 1
    he doesn't just use `wait`, he runs a function that checks for the existence of a specific DOM element, and waits for it to appear. i.e. `.wait(foo, function() { ... });`, where `foo` returns `window.document.querySelector(".my-dom-element");` – yuvi Nov 26 '14 at 16:10
  • 1
    Yeah I did that part as well – apparatix Nov 26 '14 at 16:12
  • is this code on github or anything so people can test it and make changes themselves to debug it? –  Dec 01 '14 at 18:22
  • Yup! Although the code that I posted here is a simplified version. https://github.com/ajay-gandhi/autopoke – apparatix Dec 01 '14 at 21:47
  • 1
    Try logging broser.statusCode. I suspect that the status is a redirect or something like that and that the response is indeed empty. Elsehow, you can use a tool like Fiddler to look at the actual request/response to the Openshift server, it might be useful. – Julien Bérubé Dec 04 '14 at 01:42
  • I don't think the browser has a property `statusCode`, but I logged `browser.resources` (https://github.com/assaf/zombie#resources) instead. I did not see a `response`, which I would see if I run locally. – apparatix Dec 04 '14 at 16:02

2 Answers2

1

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

Julien Bérubé
  • 1,256
  • 1
  • 13
  • 22
0

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.