-
Notifications
You must be signed in to change notification settings - Fork 2
/
phantomjs-buster.js
44 lines (35 loc) · 979 Bytes
/
phantomjs-buster.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
var page = require('webpage').create();
var url = 'http://localhost:1111/capture';
var captureAttempts = 0;
var captured = false;
var locked = false;
var log = function(str) {
var dt = new Date();
console.log(dt.toString() + ': ' + str);
};
var pageLoaded = function(status) {
log('Finished loading ' + url + ' with status: ' + status);
var runnerFrame = page.evaluate(function() {
return document.getElementById('session_frame');
});
if (!runnerFrame) {
locked = false;
setTimeout(capture, 1000);
} else {
captured = true;
}
};
var capture = function() {
if (captureAttempts === 5) {
log('Failed to capture JSTD after ' + captureAttempts + ' attempts.');
phantom.exit();
}
if (captured || locked) {
return;
}
captureAttempts += 1;
locked = true;
log('Attempting (' + captureAttempts + ') to load: ' + url);
page.open(url, pageLoaded);
};
capture();