-
Notifications
You must be signed in to change notification settings - Fork 0
/
open.phantom.js
72 lines (60 loc) · 1.95 KB
/
open.phantom.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
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
var system = require('system');
var args = system.args;
var url = args[1];
var webPage = require('webpage');
var page = webPage.create();
(function () {
page.settings.userAgent = "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_12_5) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/58.0.3029.110 Safari/537.36";
var timer;
function runTimeout() {
if (timer) {
clearTimeout(timer);
}
timer = setTimeout(function () {
timer = 0;
phantom.exit(1);
}, 30 * 1000);
}
if (!url) {
console.log(JSON.stringify({
error: 'url not exists.'
}));
phantom.exit(1);
return;
}
page.onResourceRequested = function(requestData, networkRequest) {
runTimeout();
console.log('resource:' + JSON.stringify(requestData.url));
};
page.onError = function(msg, trace) {
console.log('error:' + JSON.stringify(msg));
};
page.open(url, function(status) {
var fields = page.evaluate(function () {
// @see: https://stackoverflow.com/questions/17246309/get-all-user-defined-window-properties
// make sure it doesn't count my own properties
var results;
var currentWindow;
// create an iframe and append to body to load a clean window object
var iframe = document.createElement('iframe');
iframe.style.display = 'none';
document.body.appendChild(iframe);
// get the current list of properties on window
currentWindow = Object.getOwnPropertyNames(window);
// filter the list against the properties that exist in the clean window
results = currentWindow.filter(function(prop) {
return !iframe.contentWindow.hasOwnProperty(prop);
});
// log an array of properties that are different
document.body.removeChild(iframe);
return results;
});
console.log('global:' + JSON.stringify(fields));
setTimeout(function () {
if (timer) {
clearTimeout(timer);
}
phantom.exit(0);
}, 5000);
});
})();