ferrum 0.20.2 → 0.21.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.
- checksums.yaml +4 -4
- data/README.md +2 -4
- data/lib/ferrum/accessibility.rb +40 -6
- data/lib/ferrum/browser/command.rb +2 -11
- data/lib/ferrum/browser/options/chrome.rb +58 -1
- data/lib/ferrum/browser/options.rb +63 -9
- data/lib/ferrum/browser/process.rb +12 -4
- data/lib/ferrum/browser/xvfb.rb +22 -2
- data/lib/ferrum/browser.rb +74 -35
- data/lib/ferrum/client/web_socket.rb +13 -6
- data/lib/ferrum/client.rb +119 -81
- data/lib/ferrum/concurrency/awaitable_map.rb +171 -0
- data/lib/ferrum/concurrency/cell.rb +128 -0
- data/lib/ferrum/concurrency/dispatcher.rb +146 -0
- data/lib/ferrum/console.rb +3 -2
- data/lib/ferrum/context.rb +162 -27
- data/lib/ferrum/contexts.rb +45 -22
- data/lib/ferrum/cookies/collection.rb +93 -0
- data/lib/ferrum/cookies/cookie.rb +0 -11
- data/lib/ferrum/cookies.rb +79 -86
- data/lib/ferrum/deadline.rb +140 -0
- data/lib/ferrum/dialog.rb +22 -0
- data/lib/ferrum/downloads.rb +83 -10
- data/lib/ferrum/errors.rb +96 -6
- data/lib/ferrum/frame/dom.rb +147 -38
- data/lib/ferrum/frame/runtime.rb +40 -32
- data/lib/ferrum/frame/script.rb +7 -38
- data/lib/ferrum/frame.rb +57 -20
- data/lib/ferrum/headers.rb +32 -27
- data/lib/ferrum/interceptable/chain.rb +99 -0
- data/lib/ferrum/interceptable.rb +44 -27
- data/lib/ferrum/isolated_world.rb +9 -10
- data/lib/ferrum/keyboard.rb +27 -6
- data/lib/ferrum/mouse.rb +139 -52
- data/lib/ferrum/network/auth_request.rb +42 -7
- data/lib/ferrum/network/error.rb +34 -4
- data/lib/ferrum/network/exchange.rb +35 -7
- data/lib/ferrum/network/intercepted_request.rb +42 -9
- data/lib/ferrum/network/request.rb +33 -9
- data/lib/ferrum/network/request_params.rb +11 -2
- data/lib/ferrum/network/response.rb +23 -2
- data/lib/ferrum/network.rb +267 -64
- data/lib/ferrum/node.rb +430 -62
- data/lib/ferrum/page/animation.rb +4 -0
- data/lib/ferrum/page/cookies.rb +133 -0
- data/lib/ferrum/page/frames.rb +7 -7
- data/lib/ferrum/page/navigation.rb +430 -0
- data/lib/ferrum/page/screencast.rb +4 -0
- data/lib/ferrum/page/screenshot.rb +13 -1
- data/lib/ferrum/page/stream.rb +13 -5
- data/lib/ferrum/page/tracing.rb +12 -7
- data/lib/ferrum/page.rb +168 -190
- data/lib/ferrum/remote_object.rb +4 -0
- data/lib/ferrum/target.rb +49 -11
- data/lib/ferrum/utils/deprecate.rb +73 -2
- data/lib/ferrum/utils/poll.rb +57 -0
- data/lib/ferrum/version.rb +1 -1
- data/lib/ferrum/worker.rb +34 -19
- data/lib/ferrum.rb +5 -1
- metadata +11 -6
- data/lib/ferrum/browser/options/base.rb +0 -112
- data/lib/ferrum/client/subscriber.rb +0 -145
- data/lib/ferrum/frame/runtime/legacy.rb +0 -336
- data/lib/ferrum/utils/event.rb +0 -33
data/lib/ferrum/target.rb
CHANGED
|
@@ -9,14 +9,23 @@ module Ferrum
|
|
|
9
9
|
#
|
|
10
10
|
class Target
|
|
11
11
|
NEW_WINDOW_WAIT = ENV.fetch("FERRUM_NEW_WINDOW_WAIT", 0.3).to_f
|
|
12
|
+
WINDOW_DEPRECATED = "window? will be removed in Ferrum 0.22. Use opener_id, it is set for a target another one " \
|
|
13
|
+
"opened."
|
|
14
|
+
|
|
15
|
+
attr_reader :options
|
|
16
|
+
|
|
17
|
+
# @note The writer is a private API, Ferrum sets it.
|
|
18
|
+
attr_reader :session_id
|
|
19
|
+
|
|
20
|
+
# @api private
|
|
21
|
+
attr_writer :session_id
|
|
12
22
|
|
|
13
23
|
# You can create page yourself and assign it to target, used in cuprite
|
|
14
24
|
# where we enhance page class and build page ourselves.
|
|
25
|
+
#
|
|
26
|
+
# @api private
|
|
15
27
|
attr_writer :page
|
|
16
28
|
|
|
17
|
-
attr_reader :options
|
|
18
|
-
attr_accessor :session_id
|
|
19
|
-
|
|
20
29
|
def initialize(browser_client, session_id = nil, params = nil, implicit: false)
|
|
21
30
|
@page = nil
|
|
22
31
|
@worker = nil
|
|
@@ -33,6 +42,8 @@ module Ferrum
|
|
|
33
42
|
# @param [Hash] params
|
|
34
43
|
#
|
|
35
44
|
# @return [Hash]
|
|
45
|
+
#
|
|
46
|
+
# @api private
|
|
36
47
|
def update(params)
|
|
37
48
|
@params.merge!(params)
|
|
38
49
|
end
|
|
@@ -48,6 +59,10 @@ module Ferrum
|
|
|
48
59
|
# Connects to and returns this target's {Page}.
|
|
49
60
|
#
|
|
50
61
|
# @return [Page]
|
|
62
|
+
#
|
|
63
|
+
# @raise [TimeoutError]
|
|
64
|
+
#
|
|
65
|
+
# @note The writer is a private API, Ferrum sets it.
|
|
51
66
|
def page
|
|
52
67
|
@page ||= build_page
|
|
53
68
|
end
|
|
@@ -58,6 +73,8 @@ module Ferrum
|
|
|
58
73
|
#
|
|
59
74
|
# @raise [NoSuchTargetError] if there's no session with the target, e.g. a service worker
|
|
60
75
|
# not attached to with {Context#attach_target}.
|
|
76
|
+
#
|
|
77
|
+
# @raise [TimeoutError]
|
|
61
78
|
def worker
|
|
62
79
|
@worker ||= build_worker
|
|
63
80
|
end
|
|
@@ -76,6 +93,8 @@ module Ferrum
|
|
|
76
93
|
# @param [Hash] options
|
|
77
94
|
#
|
|
78
95
|
# @return [Page]
|
|
96
|
+
#
|
|
97
|
+
# @api private
|
|
79
98
|
def build_page(**options)
|
|
80
99
|
maybe_sleep_if_new_window
|
|
81
100
|
Page.new(client, context_id: context_id, target_id: id, **options)
|
|
@@ -84,12 +103,14 @@ module Ferrum
|
|
|
84
103
|
# Builds a {Worker} for this target. Called lazily by {#worker}.
|
|
85
104
|
#
|
|
86
105
|
# @return [Worker]
|
|
106
|
+
#
|
|
107
|
+
# @api private
|
|
87
108
|
def build_worker
|
|
88
109
|
if options.flatten && session_id.nil?
|
|
89
110
|
raise NoSuchTargetError, "No session with #{type} #{id}, attach to it with Context#attach_target first"
|
|
90
111
|
end
|
|
91
112
|
|
|
92
|
-
Worker.new(client, target_id: id, url: url)
|
|
113
|
+
Worker.new(client, target_id: id, url: url, type: type)
|
|
93
114
|
end
|
|
94
115
|
|
|
95
116
|
# Closes the WebSocket connection, without closing the target itself
|
|
@@ -155,11 +176,13 @@ module Ferrum
|
|
|
155
176
|
@params["browserContextId"] unless @implicit
|
|
156
177
|
end
|
|
157
178
|
|
|
158
|
-
# Whether this target
|
|
159
|
-
#
|
|
179
|
+
# Whether this target was opened by another one, i.e. has an {#opener_id}.
|
|
180
|
+
#
|
|
181
|
+
# @deprecated Will be removed in Ferrum 0.22. Use {#opener_id}.
|
|
160
182
|
#
|
|
161
183
|
# @return [Boolean]
|
|
162
184
|
def window?
|
|
185
|
+
Utils::Deprecate.warn(WINDOW_DEPRECATED, user_code: true)
|
|
163
186
|
!!opener_id
|
|
164
187
|
end
|
|
165
188
|
|
|
@@ -202,17 +225,32 @@ module Ferrum
|
|
|
202
225
|
# to give it a chance to load before connecting.
|
|
203
226
|
#
|
|
204
227
|
# @return [void]
|
|
228
|
+
#
|
|
229
|
+
# @api private
|
|
205
230
|
def maybe_sleep_if_new_window
|
|
206
231
|
# Dirty hack because new window doesn't have events at all
|
|
207
|
-
sleep(NEW_WINDOW_WAIT) if
|
|
232
|
+
sleep(NEW_WINDOW_WAIT) if opener_id
|
|
208
233
|
end
|
|
209
234
|
|
|
210
235
|
# Sends a CDP command through {#client}.
|
|
211
236
|
#
|
|
212
|
-
# @
|
|
213
|
-
#
|
|
214
|
-
|
|
215
|
-
|
|
237
|
+
# @param [String] method
|
|
238
|
+
# The CDP method name.
|
|
239
|
+
#
|
|
240
|
+
# @param [Numeric, Deadline, nil] timeout
|
|
241
|
+
# How long to wait for the response, the browser's `timeout` by default.
|
|
242
|
+
#
|
|
243
|
+
# @param [Hash] params
|
|
244
|
+
# The command's parameters.
|
|
245
|
+
#
|
|
246
|
+
# @return [Hash]
|
|
247
|
+
# The command's result.
|
|
248
|
+
#
|
|
249
|
+
# @raise [TimeoutError]
|
|
250
|
+
#
|
|
251
|
+
# @api private
|
|
252
|
+
def command(method, timeout: nil, **params)
|
|
253
|
+
client.command(method, timeout: timeout || client.timeout, **params)
|
|
216
254
|
end
|
|
217
255
|
|
|
218
256
|
private
|
|
@@ -3,8 +3,7 @@
|
|
|
3
3
|
module Ferrum
|
|
4
4
|
module Utils
|
|
5
5
|
#
|
|
6
|
-
# Emits deprecation warnings for
|
|
7
|
-
# old behavior is removed in the next release, Ferrum 0.21.
|
|
6
|
+
# Emits deprecation warnings for APIs removed in a later release.
|
|
8
7
|
#
|
|
9
8
|
# Warnings are printed once per unique message and call site so that a
|
|
10
9
|
# deprecated call inside a loop doesn't flood the output. Set
|
|
@@ -47,6 +46,78 @@ module Ferrum
|
|
|
47
46
|
Kernel.warn(message)
|
|
48
47
|
end
|
|
49
48
|
|
|
49
|
+
#
|
|
50
|
+
# Picks the value of a keyword argument that was renamed: warns and returns the old one when it is given,
|
|
51
|
+
# otherwise returns the current one.
|
|
52
|
+
#
|
|
53
|
+
# @param [Symbol] old
|
|
54
|
+
# The old keyword.
|
|
55
|
+
#
|
|
56
|
+
# @param [Symbol] new
|
|
57
|
+
# The new keyword.
|
|
58
|
+
#
|
|
59
|
+
# @param [Object, nil] value
|
|
60
|
+
# What was passed as the old keyword, `nil` when nothing was.
|
|
61
|
+
#
|
|
62
|
+
# @param [Object] current
|
|
63
|
+
# The value of the new keyword.
|
|
64
|
+
#
|
|
65
|
+
# @return [Object]
|
|
66
|
+
#
|
|
67
|
+
def renamed_keyword(old, new, value, current)
|
|
68
|
+
return current if value.nil?
|
|
69
|
+
|
|
70
|
+
warn(":#{old} is renamed to :#{new} and will be removed in Ferrum 0.22.", user_code: true)
|
|
71
|
+
value
|
|
72
|
+
end
|
|
73
|
+
|
|
74
|
+
#
|
|
75
|
+
# Picks the value of an argument that became a keyword: warns and returns the positional one when it is given,
|
|
76
|
+
# otherwise returns the keyword's.
|
|
77
|
+
#
|
|
78
|
+
# @param [Symbol] name
|
|
79
|
+
# The keyword.
|
|
80
|
+
#
|
|
81
|
+
# @param [Object, nil] value
|
|
82
|
+
# What was passed positionally, `nil` when nothing was.
|
|
83
|
+
#
|
|
84
|
+
# @param [Object] current
|
|
85
|
+
# The value of the keyword.
|
|
86
|
+
#
|
|
87
|
+
# @return [Object]
|
|
88
|
+
#
|
|
89
|
+
def positional(name, value, current)
|
|
90
|
+
return current if value.nil?
|
|
91
|
+
|
|
92
|
+
warn("Passing #{name} positionally will be removed in Ferrum 0.22, pass #{name}: instead.", user_code: true)
|
|
93
|
+
value
|
|
94
|
+
end
|
|
95
|
+
|
|
96
|
+
#
|
|
97
|
+
# Reads a float from an environment variable that replaced older ones: warns and falls back to the first old
|
|
98
|
+
# one that is set when the new one is not.
|
|
99
|
+
#
|
|
100
|
+
# @param [String] name
|
|
101
|
+
# The current variable.
|
|
102
|
+
#
|
|
103
|
+
# @param [Array<String>] legacy
|
|
104
|
+
# The variables it replaced.
|
|
105
|
+
#
|
|
106
|
+
# @param [Float] default
|
|
107
|
+
# Used when none is set.
|
|
108
|
+
#
|
|
109
|
+
# @return [Float]
|
|
110
|
+
#
|
|
111
|
+
def renamed_env(name, legacy, default)
|
|
112
|
+
return ENV[name].to_f if ENV.key?(name)
|
|
113
|
+
|
|
114
|
+
old = legacy.find { |n| ENV.key?(n) }
|
|
115
|
+
return default unless old
|
|
116
|
+
|
|
117
|
+
warn("#{old} is replaced by #{name} and will be removed in Ferrum 0.22.")
|
|
118
|
+
ENV[old].to_f
|
|
119
|
+
end
|
|
120
|
+
|
|
50
121
|
#
|
|
51
122
|
# Forgets which warnings have already been printed. Only useful in tests.
|
|
52
123
|
#
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module Ferrum
|
|
4
|
+
module Utils
|
|
5
|
+
#
|
|
6
|
+
# The loop behind every `wait_*` method: runs a block until it returns a
|
|
7
|
+
# truthy value or the timeout is reached, sleeping between the attempts.
|
|
8
|
+
#
|
|
9
|
+
module Poll
|
|
10
|
+
module_function
|
|
11
|
+
|
|
12
|
+
#
|
|
13
|
+
# Runs the block until it returns a truthy value. Calls in the block
|
|
14
|
+
# share the timeout, see {Deadline.within}.
|
|
15
|
+
#
|
|
16
|
+
# @param [Numeric, Deadline] timeout
|
|
17
|
+
# How long to keep trying.
|
|
18
|
+
#
|
|
19
|
+
# @param [Numeric] interval
|
|
20
|
+
# Seconds to sleep between the attempts.
|
|
21
|
+
#
|
|
22
|
+
# @yield The check to repeat.
|
|
23
|
+
#
|
|
24
|
+
# @return [Object, nil]
|
|
25
|
+
# What the block returned, `nil` if it didn't return a truthy value in time.
|
|
26
|
+
#
|
|
27
|
+
def call(timeout, interval, &)
|
|
28
|
+
deadline = Deadline.wrap(timeout)
|
|
29
|
+
Deadline.within(deadline) do
|
|
30
|
+
loop do
|
|
31
|
+
value = attempt(deadline, &)
|
|
32
|
+
return value if value
|
|
33
|
+
return if deadline.expired?
|
|
34
|
+
|
|
35
|
+
sleep([interval, deadline.remaining].min)
|
|
36
|
+
end
|
|
37
|
+
end
|
|
38
|
+
end
|
|
39
|
+
|
|
40
|
+
#
|
|
41
|
+
# Runs the block once, turning a {TimeoutError} it raises into `nil`
|
|
42
|
+
# once the deadline has expired.
|
|
43
|
+
#
|
|
44
|
+
# @param [Deadline] deadline
|
|
45
|
+
#
|
|
46
|
+
# @return [Object, nil]
|
|
47
|
+
#
|
|
48
|
+
def attempt(deadline)
|
|
49
|
+
yield
|
|
50
|
+
rescue TimeoutError
|
|
51
|
+
raise unless deadline.expired?
|
|
52
|
+
|
|
53
|
+
nil
|
|
54
|
+
end
|
|
55
|
+
end
|
|
56
|
+
end
|
|
57
|
+
end
|
data/lib/ferrum/version.rb
CHANGED
data/lib/ferrum/worker.rb
CHANGED
|
@@ -17,15 +17,16 @@ module Ferrum
|
|
|
17
17
|
# @return [Client, SessionClient]
|
|
18
18
|
attr_reader :client
|
|
19
19
|
|
|
20
|
-
attr_reader :target_id, :url
|
|
20
|
+
attr_reader :target_id, :url, :type
|
|
21
21
|
|
|
22
|
-
def initialize(client, target_id:, url:)
|
|
22
|
+
def initialize(client, target_id:, url:, type: "worker")
|
|
23
23
|
@client = client
|
|
24
24
|
@target_id = target_id
|
|
25
25
|
@url = url
|
|
26
|
+
@type = type
|
|
26
27
|
@options = client.options
|
|
27
28
|
@page = self
|
|
28
|
-
@execution_id =
|
|
29
|
+
@execution_id = Concurrency::Cell.new
|
|
29
30
|
@network = Network.new(self)
|
|
30
31
|
@console = Console.new(self)
|
|
31
32
|
|
|
@@ -52,10 +53,21 @@ module Ferrum
|
|
|
52
53
|
|
|
53
54
|
# Sends a CDP command through {#client}.
|
|
54
55
|
#
|
|
55
|
-
# @
|
|
56
|
-
#
|
|
57
|
-
|
|
58
|
-
|
|
56
|
+
# @param [String] method
|
|
57
|
+
# The CDP method name.
|
|
58
|
+
#
|
|
59
|
+
# @param [Numeric, Deadline, nil] timeout
|
|
60
|
+
# How long to wait for the response, the worker's `timeout` by default.
|
|
61
|
+
#
|
|
62
|
+
# @param [Hash] params
|
|
63
|
+
# The command's parameters.
|
|
64
|
+
#
|
|
65
|
+
# @return [Hash]
|
|
66
|
+
# The command's result.
|
|
67
|
+
#
|
|
68
|
+
# @raise [TimeoutError]
|
|
69
|
+
def command(method, timeout: nil, **params)
|
|
70
|
+
client.command(method, timeout: timeout || self.timeout, **params)
|
|
59
71
|
end
|
|
60
72
|
|
|
61
73
|
# Workers have a single execution context and no navigable document, so
|
|
@@ -64,14 +76,19 @@ module Ferrum
|
|
|
64
76
|
nil
|
|
65
77
|
end
|
|
66
78
|
|
|
67
|
-
# Closes the
|
|
79
|
+
# Closes the worker in the browser, and its connection. Chrome refuses
|
|
80
|
+
# `Target.closeTarget` for a dedicated worker, so it closes itself instead.
|
|
68
81
|
#
|
|
69
|
-
# @return [
|
|
82
|
+
# @return [nil]
|
|
70
83
|
def close
|
|
71
|
-
|
|
84
|
+
if type == "worker"
|
|
85
|
+
client.notify("Runtime.evaluate", expression: "self.close()")
|
|
86
|
+
else
|
|
87
|
+
client.notify("Target.closeTarget", targetId: target_id)
|
|
88
|
+
end
|
|
72
89
|
close_connection
|
|
73
90
|
|
|
74
|
-
|
|
91
|
+
nil
|
|
75
92
|
end
|
|
76
93
|
|
|
77
94
|
# Closes the WebSocket connection only, without asking the browser to
|
|
@@ -115,18 +132,16 @@ module Ferrum
|
|
|
115
132
|
command("Runtime.runIfWaitingForDebugger")
|
|
116
133
|
end
|
|
117
134
|
|
|
118
|
-
def execution_id!
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
value
|
|
135
|
+
def execution_id!(timeout = nil)
|
|
136
|
+
@execution_id.wait(timeout || self.timeout)
|
|
137
|
+
@execution_id.value || raise(NoExecutionContextError)
|
|
123
138
|
end
|
|
124
139
|
|
|
125
140
|
def execution_id=(value)
|
|
126
141
|
if value.nil?
|
|
127
|
-
@execution_id.
|
|
128
|
-
|
|
129
|
-
@execution_id.
|
|
142
|
+
@execution_id.clear
|
|
143
|
+
elsif !@execution_id.set?
|
|
144
|
+
@execution_id.set(value)
|
|
130
145
|
end
|
|
131
146
|
end
|
|
132
147
|
end
|
data/lib/ferrum.rb
CHANGED
|
@@ -2,11 +2,15 @@
|
|
|
2
2
|
|
|
3
3
|
require "concurrent-ruby"
|
|
4
4
|
require "ferrum/version"
|
|
5
|
-
require "ferrum/utils/event"
|
|
6
5
|
require "ferrum/utils/thread"
|
|
7
6
|
require "ferrum/utils/platform"
|
|
8
7
|
require "ferrum/utils/elapsed_time"
|
|
8
|
+
require "ferrum/deadline"
|
|
9
|
+
require "ferrum/concurrency/cell"
|
|
10
|
+
require "ferrum/concurrency/awaitable_map"
|
|
11
|
+
require "ferrum/concurrency/dispatcher"
|
|
9
12
|
require "ferrum/utils/attempt"
|
|
13
|
+
require "ferrum/utils/poll"
|
|
10
14
|
require "ferrum/utils/deprecate"
|
|
11
15
|
require "ferrum/errors"
|
|
12
16
|
require "ferrum/browser"
|
metadata
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: ferrum
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 0.
|
|
4
|
+
version: 0.21.0
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Dmitry Vorotilin
|
|
@@ -81,7 +81,6 @@ files:
|
|
|
81
81
|
- lib/ferrum/browser/binary.rb
|
|
82
82
|
- lib/ferrum/browser/command.rb
|
|
83
83
|
- lib/ferrum/browser/options.rb
|
|
84
|
-
- lib/ferrum/browser/options/base.rb
|
|
85
84
|
- lib/ferrum/browser/options/chrome.rb
|
|
86
85
|
- lib/ferrum/browser/process.rb
|
|
87
86
|
- lib/ferrum/browser/process/killer.rb
|
|
@@ -89,25 +88,29 @@ files:
|
|
|
89
88
|
- lib/ferrum/browser/version_info.rb
|
|
90
89
|
- lib/ferrum/browser/xvfb.rb
|
|
91
90
|
- lib/ferrum/client.rb
|
|
92
|
-
- lib/ferrum/client/subscriber.rb
|
|
93
91
|
- lib/ferrum/client/web_socket.rb
|
|
92
|
+
- lib/ferrum/concurrency/awaitable_map.rb
|
|
93
|
+
- lib/ferrum/concurrency/cell.rb
|
|
94
|
+
- lib/ferrum/concurrency/dispatcher.rb
|
|
94
95
|
- lib/ferrum/console.rb
|
|
95
96
|
- lib/ferrum/console/location.rb
|
|
96
97
|
- lib/ferrum/console/message.rb
|
|
97
98
|
- lib/ferrum/context.rb
|
|
98
99
|
- lib/ferrum/contexts.rb
|
|
99
100
|
- lib/ferrum/cookies.rb
|
|
101
|
+
- lib/ferrum/cookies/collection.rb
|
|
100
102
|
- lib/ferrum/cookies/cookie.rb
|
|
103
|
+
- lib/ferrum/deadline.rb
|
|
101
104
|
- lib/ferrum/dialog.rb
|
|
102
105
|
- lib/ferrum/downloads.rb
|
|
103
106
|
- lib/ferrum/errors.rb
|
|
104
107
|
- lib/ferrum/frame.rb
|
|
105
108
|
- lib/ferrum/frame/dom.rb
|
|
106
109
|
- lib/ferrum/frame/runtime.rb
|
|
107
|
-
- lib/ferrum/frame/runtime/legacy.rb
|
|
108
110
|
- lib/ferrum/frame/script.rb
|
|
109
111
|
- lib/ferrum/headers.rb
|
|
110
112
|
- lib/ferrum/interceptable.rb
|
|
113
|
+
- lib/ferrum/interceptable/chain.rb
|
|
111
114
|
- lib/ferrum/isolated_world.rb
|
|
112
115
|
- lib/ferrum/keyboard.json
|
|
113
116
|
- lib/ferrum/keyboard.rb
|
|
@@ -128,7 +131,9 @@ files:
|
|
|
128
131
|
- lib/ferrum/node.rb
|
|
129
132
|
- lib/ferrum/page.rb
|
|
130
133
|
- lib/ferrum/page/animation.rb
|
|
134
|
+
- lib/ferrum/page/cookies.rb
|
|
131
135
|
- lib/ferrum/page/frames.rb
|
|
136
|
+
- lib/ferrum/page/navigation.rb
|
|
132
137
|
- lib/ferrum/page/screencast.rb
|
|
133
138
|
- lib/ferrum/page/screenshot.rb
|
|
134
139
|
- lib/ferrum/page/stream.rb
|
|
@@ -140,8 +145,8 @@ files:
|
|
|
140
145
|
- lib/ferrum/utils/attempt.rb
|
|
141
146
|
- lib/ferrum/utils/deprecate.rb
|
|
142
147
|
- lib/ferrum/utils/elapsed_time.rb
|
|
143
|
-
- lib/ferrum/utils/event.rb
|
|
144
148
|
- lib/ferrum/utils/platform.rb
|
|
149
|
+
- lib/ferrum/utils/poll.rb
|
|
145
150
|
- lib/ferrum/utils/thread.rb
|
|
146
151
|
- lib/ferrum/version.rb
|
|
147
152
|
- lib/ferrum/worker.rb
|
|
@@ -169,7 +174,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
|
169
174
|
- !ruby/object:Gem::Version
|
|
170
175
|
version: '0'
|
|
171
176
|
requirements: []
|
|
172
|
-
rubygems_version: 4.0.
|
|
177
|
+
rubygems_version: 4.0.20
|
|
173
178
|
specification_version: 4
|
|
174
179
|
summary: Ruby headless Chrome driver
|
|
175
180
|
test_files: []
|
|
@@ -1,112 +0,0 @@
|
|
|
1
|
-
# frozen_string_literal: true
|
|
2
|
-
|
|
3
|
-
require "singleton"
|
|
4
|
-
require "open3"
|
|
5
|
-
|
|
6
|
-
module Ferrum
|
|
7
|
-
class Browser
|
|
8
|
-
class Options
|
|
9
|
-
#
|
|
10
|
-
# Abstract base for browser-specific default option builders. Subclasses
|
|
11
|
-
# (e.g. {Options::Chrome}) declare their own `DEFAULT_OPTIONS` and
|
|
12
|
-
# `PLATFORM_PATH` constants and implement {#merge_required}/{#merge_default}
|
|
13
|
-
# to produce the final CLI flags used by {Command}.
|
|
14
|
-
#
|
|
15
|
-
class Base
|
|
16
|
-
include Singleton
|
|
17
|
-
|
|
18
|
-
#
|
|
19
|
-
# Singleton instance holding the browser's default options.
|
|
20
|
-
#
|
|
21
|
-
# @return [Base]
|
|
22
|
-
#
|
|
23
|
-
def self.options
|
|
24
|
-
instance
|
|
25
|
-
end
|
|
26
|
-
|
|
27
|
-
# The installed browser's version string, obtained by running its
|
|
28
|
-
# binary with `--version`.
|
|
29
|
-
#
|
|
30
|
-
# @return [String, nil]
|
|
31
|
-
# The version output, or `nil` if the binary can't be found/run.
|
|
32
|
-
def self.version
|
|
33
|
-
out, = Open3.capture2(instance.detect_path, "--version")
|
|
34
|
-
out.strip
|
|
35
|
-
rescue Errno::ENOENT
|
|
36
|
-
nil
|
|
37
|
-
end
|
|
38
|
-
|
|
39
|
-
#
|
|
40
|
-
# Default CLI flags for the browser.
|
|
41
|
-
#
|
|
42
|
-
# @return [Hash{String => Object}]
|
|
43
|
-
#
|
|
44
|
-
def to_h
|
|
45
|
-
self.class::DEFAULT_OPTIONS
|
|
46
|
-
end
|
|
47
|
-
|
|
48
|
-
#
|
|
49
|
-
# Default CLI flags excluding the given keys.
|
|
50
|
-
#
|
|
51
|
-
# @param [Array<String>] keys
|
|
52
|
-
# Flag names to exclude.
|
|
53
|
-
#
|
|
54
|
-
# @return [Hash{String => Object}]
|
|
55
|
-
#
|
|
56
|
-
def except(*keys)
|
|
57
|
-
to_h.except(*keys)
|
|
58
|
-
end
|
|
59
|
-
|
|
60
|
-
#
|
|
61
|
-
# Locates the browser executable on the system.
|
|
62
|
-
#
|
|
63
|
-
# @return [String, nil]
|
|
64
|
-
# Absolute path to the browser binary, or `nil` if not found.
|
|
65
|
-
#
|
|
66
|
-
def detect_path
|
|
67
|
-
Binary.find(self.class::PLATFORM_PATH[Utils::Platform.platform_name])
|
|
68
|
-
end
|
|
69
|
-
|
|
70
|
-
#
|
|
71
|
-
# Merges the CLI flags that are always required to drive the browser
|
|
72
|
-
# over CDP (e.g. remote debugging port, user data dir) into `flags`.
|
|
73
|
-
# Abstract; overridden by {Options::Chrome}.
|
|
74
|
-
#
|
|
75
|
-
# @param [Hash{String => Object}] flags
|
|
76
|
-
# The flags accumulated so far.
|
|
77
|
-
# @param [Options] options
|
|
78
|
-
# The user-supplied browser options.
|
|
79
|
-
# @param [String] user_data_dir
|
|
80
|
-
# Path to the browser's user data directory.
|
|
81
|
-
#
|
|
82
|
-
# @return [Hash{String => Object}]
|
|
83
|
-
#
|
|
84
|
-
# @raise [NotImplementedError]
|
|
85
|
-
# Always, unless overridden by a subclass.
|
|
86
|
-
#
|
|
87
|
-
def merge_required(flags, options, user_data_dir)
|
|
88
|
-
raise NotImplementedError
|
|
89
|
-
end
|
|
90
|
-
|
|
91
|
-
#
|
|
92
|
-
# Merges this browser's default CLI flags (see {#to_h}) into `flags`,
|
|
93
|
-
# unless `options.ignore_default_browser_options` is set. Abstract;
|
|
94
|
-
# overridden by {Options::Chrome}.
|
|
95
|
-
#
|
|
96
|
-
# @param [Hash{String => Object}] flags
|
|
97
|
-
# The flags accumulated so far.
|
|
98
|
-
# @param [Options] options
|
|
99
|
-
# The user-supplied browser options.
|
|
100
|
-
#
|
|
101
|
-
# @return [Hash{String => Object}]
|
|
102
|
-
#
|
|
103
|
-
# @raise [NotImplementedError]
|
|
104
|
-
# Always, unless overridden by a subclass.
|
|
105
|
-
#
|
|
106
|
-
def merge_default(flags, options)
|
|
107
|
-
raise NotImplementedError
|
|
108
|
-
end
|
|
109
|
-
end
|
|
110
|
-
end
|
|
111
|
-
end
|
|
112
|
-
end
|