I have a phantomJS script that contains the following:
page.open(url, function (status) {
if (status === "fail") { /* handle failure */ }
});
The status check works sometimes, but the status will still be "success" even if the request returns 500. How can I get the actual request status code?
You can do it something like this:
So, if you need to check the status of the first browser's request (in this case google's html page) you should see it as the first one returned in
resources[0].status
. In onResourceReceived handler you can add more filters for resources you try to get http code from.UPDATE: thanks to @fotijr, added a check for completed responses
In
resources variable is undefined,
even if I set it with