This repository was archived by the owner on Jan 4, 2024. It is now read-only.
File tree Expand file tree Collapse file tree 3 files changed +30
-21
lines changed Expand file tree Collapse file tree 3 files changed +30
-21
lines changed Original file line number Diff line number Diff line change 5
5
module Gastly
6
6
class Screenshot
7
7
8
+ FetchError = Class . new ( StandardError )
9
+
8
10
SCRIPT_PATH = File . expand_path ( '../script.js' , __FILE__ )
9
11
DEFAULT_TIMEOUT = 0
10
12
DEFAULT_BROWSER_WIDTH = 1440
@@ -53,7 +55,9 @@ def capture
53
55
54
56
Phantomjs . proxy_host = proxy_host if proxy_host
55
57
Phantomjs . proxy_port = proxy_port if proxy_port
56
- Phantomjs . run ( proxy_options , SCRIPT_PATH . to_s , *prepared_params )
58
+ output = Phantomjs . run ( proxy_options , SCRIPT_PATH . to_s , *prepared_params )
59
+
60
+ raise FetchError , output if output . present?
57
61
58
62
Gastly ::Image . new ( tempfile )
59
63
end
Original file line number Diff line number Diff line change @@ -39,24 +39,29 @@ if (args.cookies !== undefined){
39
39
}
40
40
}
41
41
42
- page . open ( args . url , function ( ) {
43
- window . setTimeout ( function ( ) {
44
- page . viewportSize = { width : args . width , height : args . height } ;
45
-
46
- if ( args . selector !== undefined ) {
47
- var clipRect = page . evaluate ( function ( s ) {
48
- return document . querySelector ( s ) . getBoundingClientRect ( ) ;
49
- } , args . selector ) ;
50
-
51
- page . clipRect = {
52
- top : clipRect . top ,
53
- left : clipRect . left ,
54
- width : clipRect . width ,
55
- height : clipRect . height
56
- } ;
57
- }
58
-
59
- page . render ( args . output ) ;
42
+ page . open ( args . url , function ( status ) {
43
+ if ( status !== 'success' ) {
44
+ console . log ( 'Unable to load: ' + args . url ) ;
60
45
phantom . exit ( ) ;
61
- } , args . timeout ) ;
46
+ } else {
47
+ window . setTimeout ( function ( ) {
48
+ page . viewportSize = { width : args . width , height : args . height } ;
49
+
50
+ if ( args . selector !== undefined ) {
51
+ var clipRect = page . evaluate ( function ( s ) {
52
+ return document . querySelector ( s ) . getBoundingClientRect ( ) ;
53
+ } , args . selector ) ;
54
+
55
+ page . clipRect = {
56
+ top : clipRect . top ,
57
+ left : clipRect . left ,
58
+ width : clipRect . width ,
59
+ height : clipRect . height
60
+ } ;
61
+ }
62
+
63
+ page . render ( args . output ) ;
64
+ phantom . exit ( ) ;
65
+ } , args . timeout ) ;
66
+ }
62
67
} ) ;
Original file line number Diff line number Diff line change 1
1
module Gastly
2
- VERSION = '0.2.0 '
2
+ VERSION = '0.2.1 '
3
3
end
You can’t perform that action at this time.
0 commit comments