ferrum 0.18.0 → 0.19.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 +3 -1
- data/lib/ferrum/browser/binary.rb +1 -2
- data/lib/ferrum/browser/command.rb +0 -2
- data/lib/ferrum/browser/options/base.rb +5 -6
- data/lib/ferrum/browser/options/chrome.rb +0 -2
- data/lib/ferrum/browser/process/killer.rb +188 -0
- data/lib/ferrum/browser/process.rb +93 -88
- data/lib/ferrum/browser.rb +15 -7
- data/lib/ferrum/client/subscriber.rb +7 -2
- data/lib/ferrum/client/web_socket.rb +65 -3
- data/lib/ferrum/client.rb +28 -6
- data/lib/ferrum/context.rb +18 -5
- data/lib/ferrum/contexts.rb +75 -16
- data/lib/ferrum/downloads.rb +2 -1
- data/lib/ferrum/errors.rb +46 -2
- data/lib/ferrum/frame/dom.rb +48 -0
- data/lib/ferrum/frame/runtime.rb +9 -8
- data/lib/ferrum/interceptable.rb +25 -4
- data/lib/ferrum/page/screenshot.rb +3 -3
- data/lib/ferrum/page/stream.rb +16 -1
- data/lib/ferrum/page.rb +11 -5
- data/lib/ferrum/target.rb +7 -3
- data/lib/ferrum/utils/thread.rb +3 -1
- data/lib/ferrum/version.rb +1 -1
- data/lib/ferrum.rb +1 -1
- metadata +3 -3
- data/lib/ferrum/browser/options/firefox.rb +0 -70
data/lib/ferrum/page/stream.rb
CHANGED
|
@@ -70,7 +70,8 @@ module Ferrum
|
|
|
70
70
|
|
|
71
71
|
#
|
|
72
72
|
# Reads a CDP `IO` stream in chunks, writing each chunk to the given
|
|
73
|
-
# output until the stream is exhausted
|
|
73
|
+
# output until the stream is exhausted, then releases the stream
|
|
74
|
+
# handle on the browser side.
|
|
74
75
|
#
|
|
75
76
|
# @param [#<<] output
|
|
76
77
|
# Anything that responds to `#<<`, e.g. an open `File` or a `String`.
|
|
@@ -88,6 +89,20 @@ module Ferrum
|
|
|
88
89
|
output << chunk
|
|
89
90
|
break if result["eof"]
|
|
90
91
|
end
|
|
92
|
+
close_stream(handle: handle)
|
|
93
|
+
end
|
|
94
|
+
|
|
95
|
+
#
|
|
96
|
+
# Releases a CDP `IO` stream handle, discarding any backing storage
|
|
97
|
+
# the browser is holding for it.
|
|
98
|
+
#
|
|
99
|
+
# @param [String] handle
|
|
100
|
+
# The CDP `IO` stream handle to close.
|
|
101
|
+
#
|
|
102
|
+
# @return [void]
|
|
103
|
+
#
|
|
104
|
+
def close_stream(handle:)
|
|
105
|
+
command("IO.close", handle: handle)
|
|
91
106
|
end
|
|
92
107
|
end
|
|
93
108
|
end
|
data/lib/ferrum/page.rb
CHANGED
|
@@ -31,7 +31,7 @@ module Ferrum
|
|
|
31
31
|
|
|
32
32
|
extend Forwardable
|
|
33
33
|
|
|
34
|
-
delegate %i[at_css at_xpath css xpath
|
|
34
|
+
delegate %i[at_css at_xpath css xpath wait_for_selector
|
|
35
35
|
current_url current_title url title body doctype content=
|
|
36
36
|
execution_id execution_id! evaluate evaluate_on evaluate_async execute evaluate_func
|
|
37
37
|
add_script_tag add_style_tag] => :main_frame
|
|
@@ -176,9 +176,15 @@ module Ferrum
|
|
|
176
176
|
#
|
|
177
177
|
# @param [Float] scale_factor device scale factor value. 0 disables the override
|
|
178
178
|
#
|
|
179
|
-
# @param [Boolean] mobile whether to emulate mobile device
|
|
179
|
+
# @param [Boolean] mobile whether to emulate mobile device and enable touch
|
|
180
180
|
#
|
|
181
|
-
def set_viewport(width
|
|
181
|
+
def set_viewport(width: 0, height: 0, scale_factor: 0, mobile: false)
|
|
182
|
+
command(
|
|
183
|
+
"Emulation.setTouchEmulationEnabled",
|
|
184
|
+
enabled: mobile,
|
|
185
|
+
maxTouchPoints: 1
|
|
186
|
+
)
|
|
187
|
+
|
|
182
188
|
command(
|
|
183
189
|
"Emulation.setDeviceMetricsOverride",
|
|
184
190
|
slowmoable: true,
|
|
@@ -454,8 +460,8 @@ module Ferrum
|
|
|
454
460
|
result
|
|
455
461
|
end
|
|
456
462
|
|
|
457
|
-
# Subscribes to a CDP event, or to `:dialog`, `:request`, `:
|
|
458
|
-
# latter
|
|
463
|
+
# Subscribes to a CDP event, or to `:dialog`, `:request`, `:response`,
|
|
464
|
+
# `:auth` (the latter three handled by {Interceptable}).
|
|
459
465
|
#
|
|
460
466
|
# @param [Symbol, String] name
|
|
461
467
|
#
|
data/lib/ferrum/target.rb
CHANGED
|
@@ -17,11 +17,12 @@ module Ferrum
|
|
|
17
17
|
attr_reader :options
|
|
18
18
|
attr_accessor :session_id
|
|
19
19
|
|
|
20
|
-
def initialize(browser_client, session_id = nil, params = nil)
|
|
20
|
+
def initialize(browser_client, session_id = nil, params = nil, implicit: false)
|
|
21
21
|
@page = nil
|
|
22
22
|
@worker = nil
|
|
23
23
|
@session_id = session_id
|
|
24
24
|
@params = params
|
|
25
|
+
@implicit = implicit
|
|
25
26
|
@browser_client = browser_client
|
|
26
27
|
@options = browser_client.options
|
|
27
28
|
end
|
|
@@ -137,11 +138,14 @@ module Ferrum
|
|
|
137
138
|
@params["parentId"]
|
|
138
139
|
end
|
|
139
140
|
|
|
140
|
-
# The id of the browser context this target belongs to
|
|
141
|
+
# The id of the browser context this target belongs to, `nil` for the
|
|
142
|
+
# browser's implicit context, which Chrome doesn't let us address by id,
|
|
143
|
+
# see {Context#implicit?}. Commands scoped to a browser context target it
|
|
144
|
+
# by omitting `browserContextId`.
|
|
141
145
|
#
|
|
142
146
|
# @return [String, nil]
|
|
143
147
|
def context_id
|
|
144
|
-
@params["browserContextId"]
|
|
148
|
+
@params["browserContextId"] unless @implicit
|
|
145
149
|
end
|
|
146
150
|
|
|
147
151
|
# Whether this target is a window/tab, i.e. was opened via
|
data/lib/ferrum/utils/thread.rb
CHANGED
|
@@ -14,10 +14,12 @@ module Ferrum
|
|
|
14
14
|
#
|
|
15
15
|
# @param [Boolean] abort_on_exception
|
|
16
16
|
# Whether the thread aborts the process if it raises an unhandled exception.
|
|
17
|
+
# Off by default: an exception in one of Ferrum's own threads reaches the
|
|
18
|
+
# main thread wherever it happens to be, or kills the process outright.
|
|
17
19
|
#
|
|
18
20
|
# @return [Thread]
|
|
19
21
|
#
|
|
20
|
-
def spawn(abort_on_exception:
|
|
22
|
+
def spawn(abort_on_exception: false)
|
|
21
23
|
::Thread.new(abort_on_exception) do |whether_abort_on_exception|
|
|
22
24
|
::Thread.current.abort_on_exception = whether_abort_on_exception
|
|
23
25
|
::Thread.current.report_on_exception = true if ::Thread.current.respond_to?(:report_on_exception=)
|
data/lib/ferrum/version.rb
CHANGED
data/lib/ferrum.rb
CHANGED
|
@@ -11,7 +11,7 @@ require "ferrum/browser"
|
|
|
11
11
|
require "ferrum/node"
|
|
12
12
|
|
|
13
13
|
#
|
|
14
|
-
# Ferrum is a pure Ruby driver for headless Chrome
|
|
14
|
+
# Ferrum is a pure Ruby driver for headless Chrome. It talks
|
|
15
15
|
# directly to the browser over the Chrome DevTools Protocol (CDP), so it
|
|
16
16
|
# doesn't depend on Selenium, WebDriver or any other third party gem.
|
|
17
17
|
#
|
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.19.0
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Dmitry Vorotilin
|
|
@@ -83,8 +83,8 @@ files:
|
|
|
83
83
|
- lib/ferrum/browser/options.rb
|
|
84
84
|
- lib/ferrum/browser/options/base.rb
|
|
85
85
|
- lib/ferrum/browser/options/chrome.rb
|
|
86
|
-
- lib/ferrum/browser/options/firefox.rb
|
|
87
86
|
- lib/ferrum/browser/process.rb
|
|
87
|
+
- lib/ferrum/browser/process/killer.rb
|
|
88
88
|
- lib/ferrum/browser/version_info.rb
|
|
89
89
|
- lib/ferrum/browser/xvfb.rb
|
|
90
90
|
- lib/ferrum/client.rb
|
|
@@ -155,7 +155,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
|
155
155
|
- !ruby/object:Gem::Version
|
|
156
156
|
version: '0'
|
|
157
157
|
requirements: []
|
|
158
|
-
rubygems_version: 4.0.
|
|
158
|
+
rubygems_version: 4.0.6
|
|
159
159
|
specification_version: 4
|
|
160
160
|
summary: Ruby headless Chrome driver
|
|
161
161
|
test_files: []
|
|
@@ -1,70 +0,0 @@
|
|
|
1
|
-
# frozen_string_literal: true
|
|
2
|
-
|
|
3
|
-
module Ferrum
|
|
4
|
-
class Browser
|
|
5
|
-
class Options
|
|
6
|
-
#
|
|
7
|
-
# Firefox-specific default flags and binary locations. Provides the CLI
|
|
8
|
-
# flags required to drive Firefox over CDP (remote debugger address and
|
|
9
|
-
# profile directory) along with its (minimal) set of default flags.
|
|
10
|
-
#
|
|
11
|
-
class Firefox < Base
|
|
12
|
-
DEFAULT_OPTIONS = {
|
|
13
|
-
"headless" => nil
|
|
14
|
-
}.freeze
|
|
15
|
-
|
|
16
|
-
MAC_BIN_PATH = [
|
|
17
|
-
"/Applications/Firefox.app/Contents/MacOS/firefox-bin"
|
|
18
|
-
].freeze
|
|
19
|
-
LINUX_BIN_PATH = %w[firefox].freeze
|
|
20
|
-
WINDOWS_BIN_PATH = [
|
|
21
|
-
"C:/Program Files/Firefox Developer Edition/firefox.exe",
|
|
22
|
-
"C:/Program Files/Mozilla Firefox/firefox.exe"
|
|
23
|
-
].freeze
|
|
24
|
-
PLATFORM_PATH = {
|
|
25
|
-
mac: MAC_BIN_PATH,
|
|
26
|
-
windows: WINDOWS_BIN_PATH,
|
|
27
|
-
linux: LINUX_BIN_PATH
|
|
28
|
-
}.freeze
|
|
29
|
-
|
|
30
|
-
#
|
|
31
|
-
# Merges CLI flags required for Firefox to work with CDP.
|
|
32
|
-
#
|
|
33
|
-
# @param [Hash] flags
|
|
34
|
-
# Flags to merge required ones into.
|
|
35
|
-
#
|
|
36
|
-
# @param [Ferrum::Browser::Options] options
|
|
37
|
-
# Browser options.
|
|
38
|
-
#
|
|
39
|
-
# @param [String] user_data_dir
|
|
40
|
-
# Path to the browser's profile directory.
|
|
41
|
-
#
|
|
42
|
-
# @return [Hash]
|
|
43
|
-
# Merged flags.
|
|
44
|
-
#
|
|
45
|
-
def merge_required(flags, options, user_data_dir)
|
|
46
|
-
flags.merge("remote-debugger" => "#{options.host}:#{options.port}", "profile" => user_data_dir)
|
|
47
|
-
end
|
|
48
|
-
|
|
49
|
-
#
|
|
50
|
-
# Merges Firefox's default flags with the given ones.
|
|
51
|
-
#
|
|
52
|
-
# @param [Hash] flags
|
|
53
|
-
# Flags that take precedence over the defaults.
|
|
54
|
-
#
|
|
55
|
-
# @param [Ferrum::Browser::Options] options
|
|
56
|
-
# Browser options.
|
|
57
|
-
#
|
|
58
|
-
# @return [Hash]
|
|
59
|
-
# Merged flags.
|
|
60
|
-
#
|
|
61
|
-
def merge_default(flags, options)
|
|
62
|
-
defaults = except("headless") unless options.headless
|
|
63
|
-
|
|
64
|
-
defaults ||= DEFAULT_OPTIONS
|
|
65
|
-
defaults.merge(flags)
|
|
66
|
-
end
|
|
67
|
-
end
|
|
68
|
-
end
|
|
69
|
-
end
|
|
70
|
-
end
|