This function allows you to execute any JavaScript code like the evaluate
API function.
But it will evaluate your code asynchronous. It means:
- Current execution context will not be blocked.
- It will not return any result.
Let's say you want execute some long-running JavaScript code, but you don't interested in its result. If you will use evaluate
, your current execution context will be blocked.
The documentation for evaluateAsync
is a bit wrong. The correct signature for evaluateAsync
is:
evaluateAsync(function, ms, args)
, where:
- function - the function to evaluate
- ms - time to wait before execution
- args - function arguments
Example:
evaluateAsync(function() {
console.log('Hi! I\'m evaluateAsync call!');
}, 1000);
Using in the real world:
- You want to capture some asynchronous events.
- Unit testing! AFAIK, PhantomJS runners use
evaluateAsync
to run unit tests.