ferrum 0.10.1 → 0.12

Sign up to get free protection for your applications and to get access to all the features.
Files changed (45) hide show
  1. checksums.yaml +4 -4
  2. data/LICENSE +1 -1
  3. data/README.md +261 -28
  4. data/lib/ferrum/browser/binary.rb +46 -0
  5. data/lib/ferrum/browser/client.rb +15 -12
  6. data/lib/ferrum/browser/command.rb +7 -8
  7. data/lib/ferrum/browser/options/base.rb +1 -7
  8. data/lib/ferrum/browser/options/chrome.rb +17 -10
  9. data/lib/ferrum/browser/options/firefox.rb +11 -4
  10. data/lib/ferrum/browser/process.rb +41 -35
  11. data/lib/ferrum/browser/subscriber.rb +1 -3
  12. data/lib/ferrum/browser/web_socket.rb +9 -12
  13. data/lib/ferrum/browser/xvfb.rb +4 -8
  14. data/lib/ferrum/browser.rb +49 -12
  15. data/lib/ferrum/context.rb +12 -4
  16. data/lib/ferrum/contexts.rb +13 -9
  17. data/lib/ferrum/cookies.rb +10 -9
  18. data/lib/ferrum/errors.rb +115 -0
  19. data/lib/ferrum/frame/runtime.rb +20 -17
  20. data/lib/ferrum/frame.rb +32 -24
  21. data/lib/ferrum/headers.rb +2 -2
  22. data/lib/ferrum/keyboard.rb +11 -11
  23. data/lib/ferrum/mouse.rb +8 -7
  24. data/lib/ferrum/network/auth_request.rb +7 -2
  25. data/lib/ferrum/network/exchange.rb +14 -10
  26. data/lib/ferrum/network/intercepted_request.rb +10 -8
  27. data/lib/ferrum/network/request.rb +5 -0
  28. data/lib/ferrum/network/response.rb +4 -4
  29. data/lib/ferrum/network.rb +124 -35
  30. data/lib/ferrum/node.rb +98 -40
  31. data/lib/ferrum/page/animation.rb +15 -0
  32. data/lib/ferrum/page/frames.rb +46 -15
  33. data/lib/ferrum/page/screenshot.rb +53 -67
  34. data/lib/ferrum/page/stream.rb +38 -0
  35. data/lib/ferrum/page/tracing.rb +71 -0
  36. data/lib/ferrum/page.rb +88 -34
  37. data/lib/ferrum/proxy.rb +58 -0
  38. data/lib/ferrum/{rbga.rb → rgba.rb} +4 -2
  39. data/lib/ferrum/target.rb +1 -0
  40. data/lib/ferrum/utils/attempt.rb +20 -0
  41. data/lib/ferrum/utils/elapsed_time.rb +27 -0
  42. data/lib/ferrum/utils/platform.rb +28 -0
  43. data/lib/ferrum/version.rb +1 -1
  44. data/lib/ferrum.rb +4 -140
  45. metadata +65 -50
@@ -0,0 +1,28 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Ferrum
4
+ module Utils
5
+ module Platform
6
+ module_function
7
+
8
+ def name
9
+ return :mac if mac?
10
+ return :windows if windows?
11
+
12
+ :linux
13
+ end
14
+
15
+ def windows?
16
+ RbConfig::CONFIG["host_os"] =~ /mingw|mswin|cygwin/
17
+ end
18
+
19
+ def mac?
20
+ RbConfig::CONFIG["host_os"] =~ /darwin/
21
+ end
22
+
23
+ def mri?
24
+ defined?(RUBY_ENGINE) && RUBY_ENGINE == "ruby"
25
+ end
26
+ end
27
+ end
28
+ end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Ferrum
4
- VERSION = "0.10.1"
4
+ VERSION = "0.12"
5
5
  end
data/lib/ferrum.rb CHANGED
@@ -1,147 +1,11 @@
1
1
  # frozen_string_literal: true
2
2
 
3
+ require "ferrum/utils/platform"
4
+ require "ferrum/utils/elapsed_time"
5
+ require "ferrum/utils/attempt"
6
+ require "ferrum/errors"
3
7
  require "ferrum/browser"
4
8
  require "ferrum/node"
5
9
 
6
10
  module Ferrum
7
- class Error < StandardError; end
8
- class NoSuchPageError < Error; end
9
- class NoSuchTargetError < Error; end
10
- class NotImplementedError < Error; end
11
-
12
- class StatusError < Error
13
- def initialize(url, message = nil)
14
- super(message || "Request to #{url} failed to reach server, check DNS and server status")
15
- end
16
- end
17
-
18
- class PendingConnectionsError < StatusError
19
- attr_reader :pendings
20
-
21
- def initialize(url, pendings = [])
22
- @pendings = pendings
23
-
24
- message = "Request to #{url} reached server, but there are still pending connections: #{pendings.join(', ')}"
25
-
26
- super(url, message)
27
- end
28
- end
29
-
30
- class TimeoutError < Error
31
- def message
32
- "Timed out waiting for response. It's possible that this happened " \
33
- "because something took a very long time (for example a page load " \
34
- "was slow). If so, setting the :timeout option to a higher value might " \
35
- "help."
36
- end
37
- end
38
-
39
- class ScriptTimeoutError < Error
40
- def message
41
- "Timed out waiting for evaluated script to return a value"
42
- end
43
- end
44
-
45
- class ProcessTimeoutError < Error
46
- attr_reader :output
47
-
48
- def initialize(timeout, output)
49
- @output = output
50
- super("Browser did not produce websocket url within #{timeout} seconds, try to increase `:process_timeout`. See https://github.com/rubycdp/ferrum#customization")
51
- end
52
- end
53
-
54
- class DeadBrowserError < Error
55
- def initialize(message = "Browser is dead or given window is closed")
56
- super
57
- end
58
- end
59
-
60
- class NodeIsMovingError < Error
61
- def initialize(node, prev, current)
62
- @node, @prev, @current = node, prev, current
63
- super(message)
64
- end
65
-
66
- def message
67
- "#{@node.inspect} that you're trying to click is moving, hence " \
68
- "we cannot. Previosuly it was at #{@prev.inspect} but now at " \
69
- "#{@current.inspect}."
70
- end
71
- end
72
-
73
- class BrowserError < Error
74
- attr_reader :response
75
-
76
- def initialize(response)
77
- @response = response
78
- super(response["message"])
79
- end
80
-
81
- def code
82
- response["code"]
83
- end
84
-
85
- def data
86
- response["data"]
87
- end
88
- end
89
-
90
- class NodeNotFoundError < BrowserError; end
91
-
92
- class NoExecutionContextError < BrowserError
93
- def initialize(response = nil)
94
- response ||= { "message" => "There's no context available" }
95
- super(response)
96
- end
97
- end
98
-
99
- class JavaScriptError < BrowserError
100
- attr_reader :class_name, :message
101
-
102
- def initialize(response)
103
- @class_name, @message = response.values_at("className", "description")
104
- super(response.merge("message" => @message))
105
- end
106
- end
107
-
108
- class << self
109
- def windows?
110
- RbConfig::CONFIG["host_os"] =~ /mingw|mswin|cygwin/
111
- end
112
-
113
- def mac?
114
- RbConfig::CONFIG["host_os"] =~ /darwin/
115
- end
116
-
117
- def mri?
118
- defined?(RUBY_ENGINE) && RUBY_ENGINE == "ruby"
119
- end
120
-
121
- def started
122
- @@started ||= monotonic_time
123
- end
124
-
125
- def elapsed_time(start = nil)
126
- monotonic_time - (start || @@started)
127
- end
128
-
129
- def monotonic_time
130
- Concurrent.monotonic_time
131
- end
132
-
133
- def timeout?(start, timeout)
134
- elapsed_time(start) > timeout
135
- end
136
-
137
- def with_attempts(errors:, max:, wait:)
138
- attempts ||= 1
139
- yield
140
- rescue *Array(errors)
141
- raise if attempts >= max
142
- attempts += 1
143
- sleep(wait)
144
- retry
145
- end
146
- end
147
11
  end
metadata CHANGED
@@ -1,119 +1,119 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ferrum
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.10.1
4
+ version: '0.12'
5
5
  platform: ruby
6
6
  authors:
7
7
  - Dmitry Vorotilin
8
- autorequire:
8
+ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2021-02-24 00:00:00.000000000 Z
11
+ date: 2022-09-13 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
- name: websocket-driver
14
+ name: addressable
15
15
  requirement: !ruby/object:Gem::Requirement
16
16
  requirements:
17
- - - ">="
18
- - !ruby/object:Gem::Version
19
- version: '0.6'
20
- - - "<"
17
+ - - "~>"
21
18
  - !ruby/object:Gem::Version
22
- version: '0.8'
19
+ version: '2.5'
23
20
  type: :runtime
24
21
  prerelease: false
25
22
  version_requirements: !ruby/object:Gem::Requirement
26
23
  requirements:
27
- - - ">="
28
- - !ruby/object:Gem::Version
29
- version: '0.6'
30
- - - "<"
24
+ - - "~>"
31
25
  - !ruby/object:Gem::Version
32
- version: '0.8'
26
+ version: '2.5'
33
27
  - !ruby/object:Gem::Dependency
34
- name: cliver
28
+ name: concurrent-ruby
35
29
  requirement: !ruby/object:Gem::Requirement
36
30
  requirements:
37
31
  - - "~>"
38
32
  - !ruby/object:Gem::Version
39
- version: '0.3'
33
+ version: '1.1'
40
34
  type: :runtime
41
35
  prerelease: false
42
36
  version_requirements: !ruby/object:Gem::Requirement
43
37
  requirements:
44
38
  - - "~>"
45
39
  - !ruby/object:Gem::Version
46
- version: '0.3'
40
+ version: '1.1'
47
41
  - !ruby/object:Gem::Dependency
48
- name: concurrent-ruby
42
+ name: webrick
49
43
  requirement: !ruby/object:Gem::Requirement
50
44
  requirements:
51
45
  - - "~>"
52
46
  - !ruby/object:Gem::Version
53
- version: '1.1'
47
+ version: '1.7'
54
48
  type: :runtime
55
49
  prerelease: false
56
50
  version_requirements: !ruby/object:Gem::Requirement
57
51
  requirements:
58
52
  - - "~>"
59
53
  - !ruby/object:Gem::Version
60
- version: '1.1'
54
+ version: '1.7'
61
55
  - !ruby/object:Gem::Dependency
62
- name: addressable
56
+ name: websocket-driver
63
57
  requirement: !ruby/object:Gem::Requirement
64
58
  requirements:
65
- - - "~>"
59
+ - - ">="
66
60
  - !ruby/object:Gem::Version
67
- version: '2.5'
61
+ version: '0.6'
62
+ - - "<"
63
+ - !ruby/object:Gem::Version
64
+ version: '0.8'
68
65
  type: :runtime
69
66
  prerelease: false
70
67
  version_requirements: !ruby/object:Gem::Requirement
71
68
  requirements:
72
- - - "~>"
69
+ - - ">="
73
70
  - !ruby/object:Gem::Version
74
- version: '2.5'
71
+ version: '0.6'
72
+ - - "<"
73
+ - !ruby/object:Gem::Version
74
+ version: '0.8'
75
75
  - !ruby/object:Gem::Dependency
76
- name: rake
76
+ name: chunky_png
77
77
  requirement: !ruby/object:Gem::Requirement
78
78
  requirements:
79
79
  - - "~>"
80
80
  - !ruby/object:Gem::Version
81
- version: '13.0'
81
+ version: '1.3'
82
82
  type: :development
83
83
  prerelease: false
84
84
  version_requirements: !ruby/object:Gem::Requirement
85
85
  requirements:
86
86
  - - "~>"
87
87
  - !ruby/object:Gem::Version
88
- version: '13.0'
88
+ version: '1.3'
89
89
  - !ruby/object:Gem::Dependency
90
- name: rspec
90
+ name: image_size
91
91
  requirement: !ruby/object:Gem::Requirement
92
92
  requirements:
93
93
  - - "~>"
94
94
  - !ruby/object:Gem::Version
95
- version: '3.8'
95
+ version: '2.0'
96
96
  type: :development
97
97
  prerelease: false
98
98
  version_requirements: !ruby/object:Gem::Requirement
99
99
  requirements:
100
100
  - - "~>"
101
101
  - !ruby/object:Gem::Version
102
- version: '3.8'
102
+ version: '2.0'
103
103
  - !ruby/object:Gem::Dependency
104
- name: sinatra
104
+ name: pdf-reader
105
105
  requirement: !ruby/object:Gem::Requirement
106
106
  requirements:
107
107
  - - "~>"
108
108
  - !ruby/object:Gem::Version
109
- version: '2.0'
109
+ version: '2.2'
110
110
  type: :development
111
111
  prerelease: false
112
112
  version_requirements: !ruby/object:Gem::Requirement
113
113
  requirements:
114
114
  - - "~>"
115
115
  - !ruby/object:Gem::Version
116
- version: '2.0'
116
+ version: '2.2'
117
117
  - !ruby/object:Gem::Dependency
118
118
  name: puma
119
119
  requirement: !ruby/object:Gem::Requirement
@@ -129,47 +129,47 @@ dependencies:
129
129
  - !ruby/object:Gem::Version
130
130
  version: '4.1'
131
131
  - !ruby/object:Gem::Dependency
132
- name: image_size
132
+ name: rake
133
133
  requirement: !ruby/object:Gem::Requirement
134
134
  requirements:
135
135
  - - "~>"
136
136
  - !ruby/object:Gem::Version
137
- version: '2.0'
137
+ version: '13.0'
138
138
  type: :development
139
139
  prerelease: false
140
140
  version_requirements: !ruby/object:Gem::Requirement
141
141
  requirements:
142
142
  - - "~>"
143
143
  - !ruby/object:Gem::Version
144
- version: '2.0'
144
+ version: '13.0'
145
145
  - !ruby/object:Gem::Dependency
146
- name: pdf-reader
146
+ name: rspec
147
147
  requirement: !ruby/object:Gem::Requirement
148
148
  requirements:
149
149
  - - "~>"
150
150
  - !ruby/object:Gem::Version
151
- version: '2.2'
151
+ version: '3.8'
152
152
  type: :development
153
153
  prerelease: false
154
154
  version_requirements: !ruby/object:Gem::Requirement
155
155
  requirements:
156
156
  - - "~>"
157
157
  - !ruby/object:Gem::Version
158
- version: '2.2'
158
+ version: '3.8'
159
159
  - !ruby/object:Gem::Dependency
160
- name: chunky_png
160
+ name: sinatra
161
161
  requirement: !ruby/object:Gem::Requirement
162
162
  requirements:
163
163
  - - "~>"
164
164
  - !ruby/object:Gem::Version
165
- version: '1.3'
165
+ version: '2.0'
166
166
  type: :development
167
167
  prerelease: false
168
168
  version_requirements: !ruby/object:Gem::Requirement
169
169
  requirements:
170
170
  - - "~>"
171
171
  - !ruby/object:Gem::Version
172
- version: '1.3'
172
+ version: '2.0'
173
173
  description: Ferrum allows you to control headless Chrome browser
174
174
  email:
175
175
  - d.vorotilin@gmail.com
@@ -181,6 +181,7 @@ files:
181
181
  - README.md
182
182
  - lib/ferrum.rb
183
183
  - lib/ferrum/browser.rb
184
+ - lib/ferrum/browser/binary.rb
184
185
  - lib/ferrum/browser/client.rb
185
186
  - lib/ferrum/browser/command.rb
186
187
  - lib/ferrum/browser/options/base.rb
@@ -194,6 +195,7 @@ files:
194
195
  - lib/ferrum/contexts.rb
195
196
  - lib/ferrum/cookies.rb
196
197
  - lib/ferrum/dialog.rb
198
+ - lib/ferrum/errors.rb
197
199
  - lib/ferrum/frame.rb
198
200
  - lib/ferrum/frame/dom.rb
199
201
  - lib/ferrum/frame/runtime.rb
@@ -210,16 +212,29 @@ files:
210
212
  - lib/ferrum/network/response.rb
211
213
  - lib/ferrum/node.rb
212
214
  - lib/ferrum/page.rb
215
+ - lib/ferrum/page/animation.rb
213
216
  - lib/ferrum/page/frames.rb
214
217
  - lib/ferrum/page/screenshot.rb
215
- - lib/ferrum/rbga.rb
218
+ - lib/ferrum/page/stream.rb
219
+ - lib/ferrum/page/tracing.rb
220
+ - lib/ferrum/proxy.rb
221
+ - lib/ferrum/rgba.rb
216
222
  - lib/ferrum/target.rb
223
+ - lib/ferrum/utils/attempt.rb
224
+ - lib/ferrum/utils/elapsed_time.rb
225
+ - lib/ferrum/utils/platform.rb
217
226
  - lib/ferrum/version.rb
218
- homepage: https://github.com/route/ferrum
227
+ homepage: https://github.com/rubycdp/ferrum
219
228
  licenses:
220
229
  - MIT
221
- metadata: {}
222
- post_install_message:
230
+ metadata:
231
+ homepage_uri: https://ferrum.rubycdp.com/
232
+ bug_tracker_uri: https://github.com/rubycdp/ferrum/issues
233
+ documentation_uri: https://github.com/rubycdp/ferrum/blob/main/README.md
234
+ changelog_uri: https://github.com/rubycdp/ferrum/blob/main/CHANGELOG.md
235
+ source_code_uri: https://github.com/rubycdp/ferrum
236
+ rubygems_mfa_required: 'true'
237
+ post_install_message:
223
238
  rdoc_options: []
224
239
  require_paths:
225
240
  - lib
@@ -227,15 +242,15 @@ required_ruby_version: !ruby/object:Gem::Requirement
227
242
  requirements:
228
243
  - - ">="
229
244
  - !ruby/object:Gem::Version
230
- version: 2.3.0
245
+ version: 2.6.0
231
246
  required_rubygems_version: !ruby/object:Gem::Requirement
232
247
  requirements:
233
248
  - - ">="
234
249
  - !ruby/object:Gem::Version
235
250
  version: '0'
236
251
  requirements: []
237
- rubygems_version: 3.1.4
238
- signing_key:
252
+ rubygems_version: 3.3.7
253
+ signing_key:
239
254
  specification_version: 4
240
255
  summary: Ruby headless Chrome driver
241
256
  test_files: []