sheebz / phantom-proxy

a lightweight proxy that lets you to drive phantomjs from node.
MIT License
137 stars 34 forks source link

instead of returning data on evaluate, calling a function with return data #43

Closed yasinuslu closed 6 years ago

yasinuslu commented 11 years ago

When using evaluate() function we should be able to use a callback function for async functions.

phantomProxy.create({}, function (proxy) {
    var page = proxy.page;
    page.open('http://www.w3.org', function () {
        page.includeJs('http://code.jquery.com/jquery-latest.js', function() {
          page.evaluate(function(callback) {
            $.get('http://google.com', function() {
              var data = 'some async data';
              callback(data);
            });
          }, function(result) {
            console.log(result);  // will output 'some async data'
          });
        });
    });
});

I considered using evaluateSync() but it doesn't have any option to return a data.