lib/browser.js
function buildDOM(body,engine,url,callback){
    if(!body){
        return callback(new ScrapinodeError('The HTTP response contains an empty body: "' + body +'"'));
    }

    if(engine === 'jsdom' || engine === 'jsdom+zepto'){
        var library = engine === 'jsdom+zepto' ? zepto : jquery;
        try{
            jsdom.env({
               html: body,
               src : [library],
               done : function(err,window){
                   if(err) return callback(err);
                   if(!window) return callback(new ScrapinodeError('The "window" provides by JSDOM is falsy: ' + window));
                   window.location.href = url;
                   callback(err,window);
                   window.close();
               }
            });
        }catch(err){
            callback(err);
        }
    }else if(engine === 'cheerio'){
        try{
            var $ = cheerio.load(body);
            var window = {
                $ : $,
                location : {
                    href : url
                }
            };
            callback(null,window);
        }catch(err){
            callback(err);
        }
    }else{
        callback(new ScrapinodeError('The engine "' + engine + '" is not supported. Scrapinode only supports jsdom and cheerio.'));
    }
}
function buildDOM(body,engine,url,callback){
    if(!body){
        return callback(new ScrapinodeError('The HTTP response contains an empty body: "' + body +'"'));
    }

    if(engine === 'jsdom' || engine === 'jsdom+zepto'){
        var library = engine === 'jsdom+zepto' ? zepto : jquery;
        try{
            jsdom.env({
               html: body,
               src : [library],
               done : function(err,window){
                   if(err) return callback(err);
                   if(!window) return callback(new ScrapinodeError('The "window" provides by JSDOM is falsy: ' + window));
                   window.location.href = url;
                   callback(err,window);
                   window.close();
               }
            });
        }catch(err){
            callback(err);
        }
    }else if(engine === 'cheerio'){
        try{
            var $ = cheerio.load(body);
            var window = {
                $ : $,
                location : {
                    href : url
                }
            };
            callback(null,window);
        }catch(err){
            callback(err);
        }
    }else{
        callback(new ScrapinodeError('The engine "' + engine + '" is not supported. Scrapinode only supports jsdom and cheerio.'));
    }
}
function buildDOM ( body , engine , url , callback ) { if ( ! body ) { return callback ( new ScrapinodeError ( 'The HTTP response contains an empty body: "' + body + '"' ) ) ; } if ( engine === 'jsdom' || engine === 'jsdom+zepto' ) { var library = engine === 'jsdom+zepto' ? zepto : jquery ; try { jsdom . env ( { html : body , src : [ library ] , done : function ( err , window ) { if ( err ) return callback ( err ) ; if ( ! window ) return callback ( new ScrapinodeError ( 'The "window" provides by JSDOM is falsy: ' + window ) ) ; window . location . href = url ; callback ( err , window ) ; window . close ( ) ; } } ) ; } catch ( err ) { callback ( err ) ; } } else if ( engine === 'cheerio' ) { try { var $ = cheerio . load ( body ) ; var window = { $ : $ , location : { href : url } } ; callback ( null , window ) ; } catch ( err ) { callback ( err ) ; } } else { callback ( new ScrapinodeError ( 'The engine "' + engine + '" is not supported. Scrapinode only supports jsdom and cheerio.' ) ) ; } }
Build a DOM representation of the given HTML `body`

@param {String} body - html page
@param {String} engine - name of the engine used to generate the DOM
@param {String} url - url of the page containing the given `body`
@param {Function} callback -
@api private
Build a DOM representation of the given HTML body