Greg
Greg

Reputation: 159

Phantomjs stops loading full page

I'm using PhantomJS 1.9.7 under Debian to analyze page content. For some reason it stops loading page on any resource loading failure. For example, if it cannot load .js file, it finishes with status "fail". So I get

FAIL to load the address:xxxx caused by Operation canceled

in page.open() status handler.

How to make PhantomJS go on loading other resources even if some of them cannot be loaded?

Upvotes: 3

Views: 2968

Answers (2)

Learner
Learner

Reputation: 2339

You can find the resources that are failing by printing the error to console.

page.onResourceError = function(resourceError) {
  console.log('Unable to load resource (#' + resourceError.id + 'URL:' + resourceError.url + ')');
  console.log('Error code: ' + resourceError.errorCode + '. Description: ' + resourceError.errorString);
};

And this should print something like

Unable to load resource (#19URL:http://www.google.com)
Error code: 5. Description: Operation canceled

Upvotes: 0

Artjom B.
Artjom B.

Reputation: 61962

It is quite possible that SSL is the culprit. You could try a variety of command line options to fix the loading error like:

--ignore-ssl-errors=true
--web-security=false

If you know the resource that fails to load every time, you could explicitly abort the loading by listening to the onResourceRequested event:

page.onResourceRequested = function(requestData, networkRequest){
    if (requestData.url.indexOf("yourScript.js") !== -1) {
        networkRequest.abort();
    }
};

You could also look what kind of error this is with onResourceError.

Upvotes: 2

Related Questions