Class: Ferrum::Target
- Inherits:
-
Object
- Object
- Ferrum::Target
- Defined in:
- lib/ferrum/target.rb
Constant Summary collapse
- NEW_WINDOW_WAIT =
ENV.fetch("FERRUM_NEW_WINDOW_WAIT", 0.3).to_f
Instance Attribute Summary collapse
-
#options ⇒ Object
readonly
Returns the value of attribute options.
- #page ⇒ Object
-
#session_id ⇒ Object
Returns the value of attribute session_id.
Instance Method Summary collapse
- #build_page(**options) ⇒ Object
- #client ⇒ Object
- #command ⇒ Object
- #connected? ⇒ Boolean
- #context_id ⇒ Object
- #id ⇒ Object
- #iframe? ⇒ Boolean
-
#initialize(browser_client, session_id = nil, params = nil) ⇒ Target
constructor
A new instance of Target.
- #maybe_sleep_if_new_window ⇒ Object
- #opener_id ⇒ Object
- #title ⇒ Object
- #type ⇒ Object
- #update(params) ⇒ Object
- #url ⇒ Object
- #window? ⇒ Boolean
Constructor Details
#initialize(browser_client, session_id = nil, params = nil) ⇒ Target
Returns a new instance of Target.
14 15 16 17 18 19 20 |
# File 'lib/ferrum/target.rb', line 14 def initialize(browser_client, session_id = nil, params = nil) @page = nil @session_id = session_id @params = params @browser_client = browser_client @options = browser_client. end |
Instance Attribute Details
#options ⇒ Object (readonly)
Returns the value of attribute options.
11 12 13 |
# File 'lib/ferrum/target.rb', line 11 def @options end |
#page ⇒ Object
30 31 32 |
# File 'lib/ferrum/target.rb', line 30 def page @page ||= build_page end |
#session_id ⇒ Object
Returns the value of attribute session_id.
12 13 14 |
# File 'lib/ferrum/target.rb', line 12 def session_id @session_id end |
Instance Method Details
#build_page(**options) ⇒ Object
38 39 40 41 |
# File 'lib/ferrum/target.rb', line 38 def build_page(**) maybe_sleep_if_new_window Page.new(client, context_id: context_id, target_id: id, **) end |
#client ⇒ Object
34 35 36 |
# File 'lib/ferrum/target.rb', line 34 def client @client ||= build_client end |
#command ⇒ Object
80 81 82 |
# File 'lib/ferrum/target.rb', line 80 def command(...) client.command(...) end |
#connected? ⇒ Boolean
26 27 28 |
# File 'lib/ferrum/target.rb', line 26 def connected? !!@page end |
#context_id ⇒ Object
63 64 65 |
# File 'lib/ferrum/target.rb', line 63 def context_id @params["browserContextId"] end |
#id ⇒ Object
43 44 45 |
# File 'lib/ferrum/target.rb', line 43 def id @params["targetId"] end |
#iframe? ⇒ Boolean
71 72 73 |
# File 'lib/ferrum/target.rb', line 71 def iframe? type == "iframe" end |
#maybe_sleep_if_new_window ⇒ Object
75 76 77 78 |
# File 'lib/ferrum/target.rb', line 75 def maybe_sleep_if_new_window # Dirty hack because new window doesn't have events at all sleep(NEW_WINDOW_WAIT) if window? end |
#opener_id ⇒ Object
59 60 61 |
# File 'lib/ferrum/target.rb', line 59 def opener_id @params["openerId"] end |
#title ⇒ Object
51 52 53 |
# File 'lib/ferrum/target.rb', line 51 def title @params["title"] end |
#type ⇒ Object
47 48 49 |
# File 'lib/ferrum/target.rb', line 47 def type @params["type"] end |
#update(params) ⇒ Object
22 23 24 |
# File 'lib/ferrum/target.rb', line 22 def update(params) @params.merge!(params) end |
#url ⇒ Object
55 56 57 |
# File 'lib/ferrum/target.rb', line 55 def url @params["url"] end |
#window? ⇒ Boolean
67 68 69 |
# File 'lib/ferrum/target.rb', line 67 def window? !!opener_id end |