sgentle/phantomjs-node — pull request #145 by thoop (2014-03-15 05:22:04+00:00)
Title: onResourceRequested request.abort() fix

Currently, any function passed to onResourceRequested does not have access to request.abort() or other methods on the request object.
```
page.set('onResourceRequested', function(requestData, request) { request.abort(); //error });
```

With this change, onResourceRequested is now a first class function on the page object and takes a function and a callback. The function has access to request.abort() and can only be called in the scope of phantom, and the callback does not have access to request.abort() but can be called in the scope of the users' code.
```
page.onResourceRequested(
function(requestData, request) { request.abort(); //success! },
function(requestData) { numRequestsInFlight--; }
);
```

This is accomplished similar to `page.evaluate` where the function is turned into a string, serialized across the wire to phantomjs, and turned back into a function that can execute in the scope of the phantomjs function synchronously. Then the callback is executed asynchronously across the wire, which is why it does not have access to request.abort().

This isn't a breaking change. You can still call page.set('onResourceRequested'...) the old way and it will just overwrite the new function.