How can we use Async evaluation in phantomjs

what use of evaluateAsync and when should we use this function and what is the use of using this function. in below we see poor documentation for this:

 var webPage = require('webpage'); var page = webPage.create(); // @TODO: Finish page.evaluateJavaScript example. 

any authority can show an example using evaluateAsync in phantomjs

+6
source share
1 answer

This function allows you to execute any JavaScript code, such as the evaluate API evaluate . But it will evaluate your asynchronous code. It means:

  • The current execution context will not be blocked.
  • He will not return any result.

Suppose you want to execute some kind of long JavaScript code, but you are not interested in its result. If you use evaluate , your current execution context will be blocked.

The documentation for evaluateAsync bit erroneous. The correct signature for evaluateAsync is: evaluateAsync(function, ms, args) , where:

  • function - function to evaluate
  • ms - timeout before execution
  • arguments args - function

Example:

 evaluateAsync(function() { console.log('Hi! I\'m evaluateAsync call!'); }, 1000); 

Use in the real world:

  • You want to capture some asynchronous events.
  • Unit testing! AFAIK, PhantomJS runners use evaluateAsync to run unit tests.
+10
source

All Articles