jsdom does not parse javascript

492 views Asked by At

To explain the title a bit further, it seems like jsdom does not seem to be parsing the external/internal javascript. Either that, or I'm completely missing something here.

The following snippet is suppose to visit hulu and print out the search-container div, which I believe is added to the site dynamically through javascript. The code does not seem to work.

I don't understand why it isn't working. Any help would be appreciated.

Snippet:

var jsdom = require('jsdom');
var request = require('request');

var url = "http://www.hulu.com";


// Catch any errors.
process.on('uncaughtException', function (err) {
    console.log('Caught exception: ' + err);
});

// Request page from server.
request(url, function(error, response, body) {
    if (error)  return;

  if (!error && response.statusCode == 200) {
    console.log("Loaded webpage, parsing");
    jdom(body); // Parse page into jsdom
  }
})

function jdom(body) {

    var doc   = jsdom.jsdom(body, null, {
        features: {
            FetchExternalResources   : ['script'],
            ProcessExternalResources : ['script'],
            MutationEvents           : '2.0',
        }
    });

    var window = doc.createWindow();
    jsdom.jQueryify(window, "http://code.jquery.com/jquery-1.5.min.js", function(window)     {

        //var $ = window.$;
        var $ = window.jQuery;
        var document = window.document;

        console.log(window.$().jquery); // print jquery version


        $(document).ready(function() {
            //console.log( $('#search-container').html() );

            setInterval(function() { // waitForElement()

                console.log( $('#search-container').html() );

            }, 2000);

        });

    });

}


Result is null every 2 seconds.


It should be noted that there is an exception caught a few seconds after the above code is ran.

Exception:
Caught exception: TypeError: Cannot read property 'currentView' of undefined

0

There are 0 answers