forked from c-x/nmap-webshot
-
Notifications
You must be signed in to change notification settings - Fork 0
/
screenshot.js
53 lines (47 loc) · 1.58 KB
/
screenshot.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
//VERSION 0.2
//var width = 1280, height = 1024;
var width = 800, height = 600;
var timeout = 5000;
var page = new WebPage(), address, output;
if (phantom.args.length != 2) {
console.log('Usage: screenshot.js URL filename');
phantom.exit();
} else {
address = phantom.args[0];
output = phantom.args[1];
page.viewportSize = { width: width, height: height };
// do not cache objects
page.customHeaders = {"Pragma":"no-cache"};
page.customHeaders = {"Cache-control":"no-cache"};
var address_is_image;
page.onResourceReceived = function (response) {
if (response.url == address && response.contentType.match(/^image\/(.+)/)) {
console.log(address + ' is ' + RegExp.$1);
address_is_image = 1;
}
};
page.open(address, function (status) {
if (status !== 'success') {
console.log('Unable to load the address!');
console.log('status = ' + status);
phantom.exit();
} else {
if (address_is_image) {
try {
fs.write(output, page.content, "w");
} catch (e) {
console.log(e);
}
phantom.exit();
}
window.setTimeout(function () {
page.clipRect = { top: 0, left: 0, width: width, height: height };
page.evaluate(function() {
document.body.bgColor = 'white';
});
page.render(output);
phantom.exit();
}, timeout);
}
});
}