Add better logging to the snapshot generator for timing purposes and make sure the PhantomJS script always exists after a maximum of 10 seconds.

This commit is contained in:
Joseph Schorr 2014-05-19 13:11:07 -04:00
parent 29dc7fd079
commit 1c0c551d00
2 changed files with 45 additions and 23 deletions

View file

@ -1,37 +1,55 @@
var system = require('system');
var url = system.args[1] || '';
var count = 0;
if(url.length > 0) {
var page = require('webpage').create();
page.open(url, function (status) {
if (status == 'success') {
var delay, checker = (function() {
var html = page.evaluate(function () {
var found = document.getElementsByTagName('html')[0].outerHTML || '';
if (window.__isLoading && !window.__isLoading()) {
return found;
}
if (found.indexOf('404 Not Found') > 0) {
return found;
}
return null;
});
try {
if (status == 'success') {
var delay;
var checker = (function() {
count++;
if (html) {
if (html.indexOf('404 Not Found') > 0) {
if (count > 100) {
console.log('Not Found');
phantom.exit();
return;
return null;
}
clearTimeout(delay);
console.log(html);
phantom.exit();
}
});
delay = setInterval(checker, 100);
} else {
var html = page.evaluate(function () {
var found = document.getElementsByTagName('html')[0].outerHTML || '';
if (window.__isLoading && !window.__isLoading()) {
return found;
}
if (found.indexOf('404 Not Found') > 0) {
return found;
}
return null;
});
if (html) {
if (html.indexOf('404 Not Found') > 0) {
console.log('Not Found');
phantom.exit();
return;
}
clearTimeout(delay);
console.log(html);
phantom.exit();
}
});
delay = setInterval(checker, 100);
} else {
console.log('Not Found');
phantom.exit();
}
} catch (e) {
console.log('Not Found');
phantom.exit();
}
});
} else {
phantom.exit();
}