Proper error handling in PhantomJS driver

main
Elbert Alias 10 years ago
parent 9b2567355a
commit 79743bf227

@ -92,11 +92,20 @@
page = require('webpage').create(); page = require('webpage').create();
page.settings.loadImages = false;
page.settings.userAgent = 'Mozilla/5.0 (compatible; Wappalyzer; +https://github.com/AliasIO/Wappalyzer)';
page.settings.resourceTimeout = 3000;
page.onConsoleMessage = function(message) { page.onConsoleMessage = function(message) {
wappalyzer.log(message); wappalyzer.log(message);
}; };
page.onError = function(message) { page.onError = function(message) {
wappalyzer.log('Page error: ' + message); throw new Error(message);
};
page.onResourceTimeout = function() {
throw new Error('Resource timeout');
}; };
page.onResourceReceived = function(response) { page.onResourceReceived = function(response) {
@ -118,8 +127,6 @@
page.open(url, function(status) { page.open(url, function(status) {
var html, environmentVars; var html, environmentVars;
wappalyzer.log('page.open: ' + status);
if ( status === 'success' ) { if ( status === 'success' ) {
html = page.content; html = page.content;
@ -147,9 +154,11 @@
headers: headers, headers: headers,
env: environmentVars env: environmentVars
}); });
} else {
wappalyzer.log('Failed to fetch page');
} }
phantom.exit(); phantom.exit(status === 'success' ? 0 : 1);
}); });
} }
}; };
@ -158,6 +167,6 @@
} catch ( e ) { } catch ( e ) {
console.error(e); console.error(e);
phantom.exit(); phantom.exit(1);
} }
})(); })();