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.
source share