Class: Ferrum::Browser
- Inherits:
-
Object
show all
- Extended by:
- Forwardable
- Defined in:
- lib/ferrum/browser.rb,
lib/ferrum/browser/client.rb,
lib/ferrum/browser/process.rb,
lib/ferrum/browser/subscriber.rb,
lib/ferrum/browser/web_socket.rb
Defined Under Namespace
Classes: Client, Process, Subscriber, WebSocket
Constant Summary
collapse
- TIMEOUT =
5
- WINDOW_SIZE =
[1024, 768].freeze
- BASE_URL_SCHEMA =
%w[http https].freeze
Instance Attribute Summary collapse
Instance Method Summary
collapse
Constructor Details
#initialize(options = nil) ⇒ Browser
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
|
# File 'lib/ferrum/browser.rb', line 37
def initialize(options = nil)
options ||= {}
@client = nil
@window_size = options.fetch(:window_size, WINDOW_SIZE)
@original_window_size = @window_size
@options = Hash(options.merge(window_size: @window_size))
@logger, @timeout = @options.values_at(:logger, :timeout)
@js_errors = @options.fetch(:js_errors, false)
@slowmo = @options[:slowmo].to_i
if @options.key?(:base_url)
self.base_url = @options[:base_url]
end
if ENV["FERRUM_DEBUG"] && !@logger
STDOUT.sync = true
@logger = STDOUT
@options[:logger] = @logger
end
@options.freeze
start
end
|
Instance Attribute Details
#base_url ⇒ Object
Returns the value of attribute base_url.
34
35
36
|
# File 'lib/ferrum/browser.rb', line 34
def base_url
@base_url
end
|
#js_errors ⇒ Object
Returns the value of attribute js_errors.
34
35
36
|
# File 'lib/ferrum/browser.rb', line 34
def js_errors
@js_errors
end
|
#logger ⇒ Object
Returns the value of attribute logger.
34
35
36
|
# File 'lib/ferrum/browser.rb', line 34
def logger
@logger
end
|
#options ⇒ Object
Returns the value of attribute options.
34
35
36
|
# File 'lib/ferrum/browser.rb', line 34
def options
@options
end
|
#process ⇒ Object
Returns the value of attribute process.
34
35
36
|
# File 'lib/ferrum/browser.rb', line 34
def process
@process
end
|
#slowmo ⇒ Object
Returns the value of attribute slowmo.
34
35
36
|
# File 'lib/ferrum/browser.rb', line 34
def slowmo
@slowmo
end
|
#timeout ⇒ Object
77
78
79
|
# File 'lib/ferrum/browser.rb', line 77
def timeout
@timeout || TIMEOUT
end
|
#window_size ⇒ Object
Returns the value of attribute window_size.
18
19
20
|
# File 'lib/ferrum/browser.rb', line 18
def window_size
@window_size
end
|
Instance Method Details
#clear_memory_cache ⇒ Object
88
89
90
|
# File 'lib/ferrum/browser.rb', line 88
def clear_memory_cache
page.command("Network.clearBrowserCache")
end
|
#command(*args) ⇒ Object
81
82
83
84
85
86
|
# File 'lib/ferrum/browser.rb', line 81
def command(*args)
@client.command(*args)
rescue DeadBrowserError
restart
raise
end
|
#crash ⇒ Object
117
118
119
|
# File 'lib/ferrum/browser.rb', line 117
def crash
command("Browser.crash")
end
|
#extensions ⇒ Object
73
74
75
|
# File 'lib/ferrum/browser.rb', line 73
def extensions
@extensions ||= Array(@options[:extensions]).map { |p| File.read(p) }
end
|
#quit ⇒ Object
102
103
104
105
106
|
# File 'lib/ferrum/browser.rb', line 102
def quit
@client.close
@process.stop
@client = @process = @targets = nil
end
|
#reset ⇒ Object
92
93
94
95
|
# File 'lib/ferrum/browser.rb', line 92
def reset
@window_size = @original_window_size
targets.reset
end
|
#resize(**options) ⇒ Object
112
113
114
115
|
# File 'lib/ferrum/browser.rb', line 112
def resize(**options)
@window_size = [options[:width], options[:height]]
page.resize(**options)
end
|
#restart ⇒ Object
97
98
99
100
|
# File 'lib/ferrum/browser.rb', line 97
def restart
quit
start
end
|
#targets ⇒ Object
108
109
110
|
# File 'lib/ferrum/browser.rb', line 108
def targets
@targets ||= Targets.new(self)
end
|