alexscheelmeyer / node-phantom

bridge to PhantomJS from Node.js
317 stars 117 forks source link

Is request.abort() possible? #96

Closed Vaviloff closed 10 years ago

Vaviloff commented 10 years ago

Sometimes it is necessary to not load some urls. Here's a quote from official PhantomJS example to do it.

page.onResourceRequested = function(requestData, request) {
    if ((/http:\/\/.+?\.css/gi).test(requestData['url'])  || requestData['Content-Type'] == 'text/css') {
        console.log('The url of the request is matching. Aborting: ' + requestData['url']);
        request.abort();
    }
};

However, in node-phantom it's not possible to abort request at the time, is it?

Vaviloff commented 10 years ago

Well, as it turns out, it is possible. You just have to set page.onResourceRequested function that will be executed in the Phantomjs context.

page.setFn('onResourceRequested', function(requestData, request){
    request.abort();
});