screencap 0.1.2 → 0.1.4
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.
- checksums.yaml +4 -4
- data/lib/screencap/raster.js +35 -2
- data/lib/screencap/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 335be3e03b666778384318d5326aa80cdbac1301
|
4
|
+
data.tar.gz: a8f12091c0cd065d3fa064f07082d73e9dddae99
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 389db19dc7750dc26dfd5b0ad8e2e2e2ba0924037d7739234698b8b0f579cce3b07f1d423efb1e0d05717f0585cdb4eaf94c29345d427788accd56e3ed074b4b
|
7
|
+
data.tar.gz: 70681a3da6adf7dce7db0b28c5348aa5934c695bf773cff9b16d0843388aea12f3c1a547c77a8aeb3c3f66845e120ad1a1386d6a98c67f9318c4fdc9075a121b
|
data/lib/screencap/raster.js
CHANGED
@@ -10,6 +10,7 @@
|
|
10
10
|
// - div [optional] - a selector to use to screenshot to a specific element
|
11
11
|
// - resourceWait [optional] - default 300 - the time to wait after the last resource has loaded in MS before taking the screenshot
|
12
12
|
// - maxRenderWait [optional] - default 10000 - the maximum time to wait before taking the screenshot, regardless of whether resources are waiting to be loaded
|
13
|
+
// - cutoffWait [optional] - default null - the maximum time to wait before cutting everything off and failing...this helps if there is a page taking a long time to load
|
13
14
|
// - top, left, width, height [optional] - dimensions to use to screenshot a specific area of the screen
|
14
15
|
//
|
15
16
|
// == Important notice when providing height ==
|
@@ -20,12 +21,14 @@
|
|
20
21
|
var page = new WebPage(),
|
21
22
|
resourceWait = 300,
|
22
23
|
maxRenderWait = 10000,
|
24
|
+
cutoffWait = null,
|
23
25
|
args = {},
|
24
26
|
resourceCount = 0,
|
25
27
|
debug = false,
|
26
28
|
mask = null,
|
27
29
|
forcedRenderTimeout,
|
28
|
-
renderTimeout
|
30
|
+
renderTimeout,
|
31
|
+
cutoffTimeout;
|
29
32
|
|
30
33
|
//
|
31
34
|
// Functions
|
@@ -38,10 +41,12 @@ function pickupNamedArguments() {
|
|
38
41
|
}
|
39
42
|
|
40
43
|
if(!args.width) { args.width = 1024; }
|
44
|
+
if(!args.dpi) { args.dpi = 1; }
|
41
45
|
if(args.url) { args.url = decodeURIComponent(args.url); }
|
42
46
|
if(args.debug) { debug = true; }
|
43
47
|
if(args.resourceWait) { resourceWait = args.resourceWait; }
|
44
48
|
if(args.maxRenderWait) { maxRenderWait = args.maxRenderWait; }
|
49
|
+
if(args.cutoffWait) { cutoffWait = args.cutoffWait; }
|
45
50
|
}
|
46
51
|
|
47
52
|
function setupMask() {
|
@@ -59,14 +64,29 @@ function setupMask() {
|
|
59
64
|
function doRender() {
|
60
65
|
clearTimeout(renderTimeout);
|
61
66
|
clearTimeout(forcedRenderTimeout);
|
67
|
+
clearTimeout(cutoffTimeout);
|
62
68
|
page.render(args.output);
|
63
69
|
phantom.exit();
|
64
70
|
}
|
65
71
|
|
72
|
+
// if the page is taking too long (set via cutoffWait) to load, just exit cleanly
|
73
|
+
function cutoff() {
|
74
|
+
clearTimeout(renderTimeout);
|
75
|
+
clearTimeout(forcedRenderTimeout);
|
76
|
+
console.log('Unable to load: ' + args.url + '. Process exceeded cutoff timeout.');
|
77
|
+
phantom.exit();
|
78
|
+
}
|
79
|
+
|
66
80
|
function delayScreenshotForResources() {
|
67
81
|
forcedRenderTimeout = setTimeout(doRender, maxRenderWait);
|
68
82
|
}
|
69
83
|
|
84
|
+
function cutoffExecution() {
|
85
|
+
if(cutoffWait != null) {
|
86
|
+
cutoffTimeout = setTimeout(cutoff, cutoffWait);
|
87
|
+
}
|
88
|
+
}
|
89
|
+
|
70
90
|
function evaluateWithArgs(func) {
|
71
91
|
var args = [].slice.call(arguments, 1);
|
72
92
|
var fn = "function() { return (" + func.toString() + ").apply(this, " + JSON.stringify(args) + "); }";
|
@@ -74,12 +94,14 @@ function evaluateWithArgs(func) {
|
|
74
94
|
}
|
75
95
|
|
76
96
|
function takeScreenshot() {
|
97
|
+
cutoffExecution();
|
77
98
|
page.open(args.url, function(status) {
|
78
99
|
if(status !== 'success') {
|
79
100
|
console.log('Unable to load: ' + args.url);
|
80
101
|
phantom.exit();
|
81
102
|
} else {
|
82
103
|
delayScreenshotForResources();
|
104
|
+
|
83
105
|
page.includeJs(
|
84
106
|
"https://ajax.googleapis.com/ajax/libs/jquery/1.11.0/jquery.min.js",
|
85
107
|
function() {
|
@@ -104,10 +126,21 @@ function takeScreenshot() {
|
|
104
126
|
});
|
105
127
|
},
|
106
128
|
page.viewportSize.width,
|
107
|
-
page.viewportSize.height
|
129
|
+
page.viewportSize.height / args.dpi
|
108
130
|
);
|
109
131
|
}
|
110
132
|
|
133
|
+
if (args.dpi !== 1) {
|
134
|
+
evaluateWithArgs(
|
135
|
+
function(dpi) {
|
136
|
+
document.body.style.webkitTransform = "scale(" + dpi + ")";
|
137
|
+
document.body.style.webkitTransformOrigin = "0% 0%";
|
138
|
+
document.body.style.width = (100 / dpi) + "%";
|
139
|
+
},
|
140
|
+
args.dpi
|
141
|
+
);
|
142
|
+
}
|
143
|
+
|
111
144
|
if(!foundDiv) {
|
112
145
|
phantom.exit();
|
113
146
|
}
|
data/lib/screencap/version.rb
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: screencap
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.4
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Maxwell Salzberg
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2015-
|
12
|
+
date: 2015-07-19 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: rspec
|