wraith 2.8.1 → 3.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,5 +0,0 @@
1
- These JavaScript files have been provided by Wraith for your benefit, but you are free to edit these or add new JavaScript files if you wish.
2
-
3
- Files beginning with an underscore should not be referenced directly in your YAML files. They are 'private' modules required by some of the other modules in this directory.
4
-
5
- The two most important files to be aware of are `casper.js` and `_phantom__common.js`, as these files map Wraith's command line arguments to each respective browser engine.
@@ -1,7 +0,0 @@
1
- module.exports = function (dimensions) {
2
- dimensions = /(\d*)x?((\d*))?/i.exec(dimensions);
3
- return {
4
- 'viewportWidth': parseInt(dimensions[1]),
5
- 'viewportHeight': parseInt(dimensions[2] || 1500)
6
- };
7
- }
@@ -1,122 +0,0 @@
1
- module.exports = function (config) {
2
-
3
- // modules
4
- var page = require('webpage').create();
5
-
6
- // config
7
- var systemArgs = config.systemArgs,
8
- javascriptEnabled = config.javascriptEnabled;
9
-
10
- // command line arguments
11
- var url = systemArgs[1],
12
- dimensions = require('./_getDimensions.js')(systemArgs[2]),
13
- image_name = systemArgs[3],
14
- selector = systemArgs[4],
15
- globalBeforeCaptureJS = systemArgs[5],
16
- pathBeforeCaptureJS = systemArgs[6];
17
-
18
- globalBeforeCaptureJS = globalBeforeCaptureJS === 'false' ? false : globalBeforeCaptureJS;
19
- pathBeforeCaptureJS = pathBeforeCaptureJS === 'false' ? false : pathBeforeCaptureJS;
20
-
21
- var current_requests = 0;
22
- var last_request_timeout;
23
- var final_timeout;
24
-
25
- page.viewportSize = { width: dimensions.viewportWidth, height: dimensions.viewportHeight};
26
- page.settings = { loadImages: true, javascriptEnabled: javascriptEnabled };
27
-
28
- // If you want to use additional phantomjs commands, place them here
29
- page.settings.userAgent = 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_8_2) AppleWebKit/537.17 (KHTML, like Gecko) Chrome/28.0.1500.95 Safari/537.17';
30
-
31
- // You can place custom headers here, example below.
32
- // page.customHeaders = {
33
-
34
- // 'X-Candy-OVERRIDE': 'https://api.live.bbc.co.uk/'
35
-
36
- // };
37
-
38
- // If you want to set a cookie, just add your details below in the following way.
39
-
40
- // phantom.addCookie({
41
- // 'name': 'ckns_policy',
42
- // 'value': '111',
43
- // 'domain': '.bbc.co.uk'
44
- // });
45
- // phantom.addCookie({
46
- // 'name': 'locserv',
47
- // 'value': '1#l1#i=6691484:n=Oxford+Circus:h=e@w1#i=8:p=London@d1#1=l:2=e:3=e:4=2@n1#r=40',
48
- // 'domain': '.bbc.co.uk'
49
- // });
50
-
51
- page.onResourceRequested = function(req) {
52
- current_requests += 1;
53
- };
54
-
55
- page.onResourceReceived = function(res) {
56
- if (res.stage === 'end') {
57
- current_requests -= 1;
58
- debounced_render();
59
- }
60
- };
61
-
62
- page.open(url, function(status) {
63
- if (status !== 'success') {
64
- console.log('Error with page ' + url);
65
- phantom.exit();
66
- }
67
- });
68
-
69
-
70
- function debounced_render() {
71
- clearTimeout(last_request_timeout);
72
- clearTimeout(final_timeout);
73
-
74
- // If there's no more ongoing resource requests, wait for 1 second before
75
- // rendering, just in case the page kicks off another request
76
- if (current_requests < 1) {
77
- clearTimeout(final_timeout);
78
- last_request_timeout = setTimeout(function() {
79
-
80
- if (globalBeforeCaptureJS) {
81
- require(globalBeforeCaptureJS)(page);
82
- }
83
- if (pathBeforeCaptureJS) {
84
- require(pathBeforeCaptureJS)(page);
85
- }
86
-
87
- console.log('Snapping ' + url + ' at: ' + dimensions.viewportWidth + 'x' + dimensions.viewportHeight);
88
- page.clipRect = {
89
- top: 0,
90
- left: 0,
91
- height: dimensions.viewportHeight,
92
- width: dimensions.viewportWidth
93
- };
94
- page.render(image_name);
95
- phantom.exit();
96
- }, 1000);
97
- }
98
-
99
- // Sometimes, straggling requests never make it back, in which
100
- // case, timeout after 5 seconds and render the page anyway
101
- final_timeout = setTimeout(function() {
102
-
103
- if (globalBeforeCaptureJS) {
104
- require(globalBeforeCaptureJS)(page);
105
- }
106
- if (pathBeforeCaptureJS) {
107
- require(pathBeforeCaptureJS)(page);
108
- }
109
-
110
- console.log('Snapping ' + url + ' at: ' + dimensions.viewportWidth + 'x' + dimensions.viewportHeight);
111
- page.clipRect = {
112
- top: 0,
113
- left: 0,
114
- height: dimensions.viewportHeight,
115
- width: dimensions.viewportWidth
116
- };
117
- page.render(image_name);
118
- phantom.exit();
119
- }, 5000);
120
- }
121
-
122
- }