forked from sindresorhus/pageres
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathconverter.js
More file actions
46 lines (37 loc) · 1.01 KB
/
converter.js
File metadata and controls
46 lines (37 loc) · 1.01 KB
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
'use strict';
var webpage = require('webpage');
var page = webpage.create();
var options = JSON.parse(phantom.args[0]);
var log = console.log;
// make sure phantom never outputs to stdout
console.log = console.error;
phantom.onError = function(msg, trace) {
var msgStack = ['PHANTOM ERROR: ' + msg];
if (trace && trace.length) {
msgStack.push('TRACE:');
trace.forEach(function(t) {
msgStack.push(' -> ' + (t.file || t.sourceURL) + ': ' + t.line + (t.function ? ' (in function ' + t.function +')' : ''));
});
}
console.error(msgStack.join('\n'));
};
page.onError = function (err) {
console.error(err);
};
page.open(options.url, function (status) {
if (status === 'fail') {
console.error('Couldn\'t load url');
phantom.exit(1);
}
page.viewportSize = {
width: options.width,
height: options.height
};
page.evaluate(function () {
document.body.bgColor = 'white';
});
window.setTimeout(function () {
log.call(console, page.renderBase64('png'));
phantom.exit(0);
}, options.renderDelay);
});