Class: Ferrum::Frame
- Inherits:
-
Object
- Object
- Ferrum::Frame
- Defined in:
- lib/ferrum/frame.rb,
lib/ferrum/frame/dom.rb,
lib/ferrum/frame/runtime.rb
Defined Under Namespace
Constant Summary collapse
- STATE_VALUES =
i[ started_loading navigated stopped_loading ].freeze
Constants included from Runtime
Runtime::INTERMITTENT_ATTEMPTS, Runtime::INTERMITTENT_SLEEP
Constants included from DOM
DOM::LINK_TAG, DOM::SCRIPT_SRC_TAG, DOM::SCRIPT_TEXT_TAG, DOM::STYLE_TAG
Instance Attribute Summary collapse
-
#id ⇒ String
The Frame’s unique id.
-
#name ⇒ String?
If frame was given a name it should be here.
-
#page ⇒ Page
readonly
The page the frame belongs to.
-
#parent_id ⇒ String?
readonly
Parent frame id if this one is nested in another one.
-
#state ⇒ :started_loading, ...
One of the states frame’s in.
Instance Method Summary collapse
-
#content=(html) ⇒ Object
(also: #set_content)
Sets a content of a given frame.
-
#execution_id ⇒ Integer?
Execution context id which is used by JS, each frame has it’s own context in which JS evaluates.
-
#execution_id! ⇒ Integer
Execution context id which is used by JS, each frame has it’s own context in which JS evaluates.
- #execution_id=(value) ⇒ Object
-
#initialize(id, page, parent_id = nil) ⇒ Frame
constructor
A new instance of Frame.
- #inspect ⇒ Object
-
#main? ⇒ Boolean
If current frame is the main frame of the page (top of the tree).
-
#parent ⇒ Frame?
Returns the parent frame if this frame is nested in another one.
-
#title ⇒ String
Returns current frame’s title.
-
#url ⇒ String
Returns current frame’s ‘location.href`.
Methods included from Runtime
#evaluate, #evaluate_async, #evaluate_func, #evaluate_on, #execute
Methods included from DOM
#add_script_tag, #add_style_tag, #at_css, #at_xpath, #body, #css, #current_title, #current_url, #doctype, #frame_element, #xpath
Constructor Details
#initialize(id, page, parent_id = nil) ⇒ Frame
Returns a new instance of Frame.
42 43 44 45 46 47 |
# File 'lib/ferrum/frame.rb', line 42 def initialize(id, page, parent_id = nil) @id = id @page = page @parent_id = parent_id @execution_id = Concurrent::MVar.new end |
Instance Attribute Details
#id ⇒ String
The Frame’s unique id.
20 21 22 |
# File 'lib/ferrum/frame.rb', line 20 def id @id end |
#name ⇒ String?
If frame was given a name it should be here.
25 26 27 |
# File 'lib/ferrum/frame.rb', line 25 def name @name end |
#page ⇒ Page (readonly)
The page the frame belongs to.
30 31 32 |
# File 'lib/ferrum/frame.rb', line 30 def page @page end |
#parent_id ⇒ String? (readonly)
Parent frame id if this one is nested in another one.
35 36 37 |
# File 'lib/ferrum/frame.rb', line 35 def parent_id @parent_id end |
#state ⇒ :started_loading, ...
One of the states frame’s in.
40 41 42 |
# File 'lib/ferrum/frame.rb', line 40 def state @state end |
Instance Method Details
#content=(html) ⇒ Object Also known as: set_content
Sets a content of a given frame.
126 127 128 129 130 131 132 133 134 |
# File 'lib/ferrum/frame.rb', line 126 def content=(html) evaluate_async(%( document.open(); document.write(arguments[0]); document.close(); arguments[1](true); ), @page.timeout, html) @page.document_node_id end |
#execution_id ⇒ Integer?
Execution context id which is used by JS, each frame has it’s own context in which JS evaluates.
160 161 162 163 164 165 |
# File 'lib/ferrum/frame.rb', line 160 def execution_id value = @execution_id.value return if value.instance_of?(Object) value end |
#execution_id! ⇒ Integer
Execution context id which is used by JS, each frame has it’s own context in which JS evaluates. Locks for a page timeout and raises an error if an execution id hasn’t been set yet, if id is set returns immediately.
147 148 149 150 151 152 |
# File 'lib/ferrum/frame.rb', line 147 def execution_id! value = @execution_id.borrow(@page.timeout, &:itself) raise NoExecutionContextError if value.instance_of?(Object) value end |
#execution_id=(value) ⇒ Object
167 168 169 170 171 172 173 |
# File 'lib/ferrum/frame.rb', line 167 def execution_id=(value) if value.nil? @execution_id.try_take! else @execution_id.try_put!(value) end end |
#inspect ⇒ Object
175 176 177 178 179 180 181 182 |
# File 'lib/ferrum/frame.rb', line 175 def inspect "#<#{self.class} " \ "@id=#{@id.inspect} " \ "@parent_id=#{@parent_id.inspect} " \ "@name=#{@name.inspect} " \ "@state=#{@state.inspect} " \ "@execution_id=#{@execution_id.inspect}>" end |
#main? ⇒ Boolean
If current frame is the main frame of the page (top of the tree).
93 94 95 |
# File 'lib/ferrum/frame.rb', line 93 def main? @parent_id.nil? end |
#parent ⇒ Frame?
Returns the parent frame if this frame is nested in another one.
110 111 112 |
# File 'lib/ferrum/frame.rb', line 110 def parent @page.frame_by(id: @parent_id) if @parent_id end |
#title ⇒ String
Returns current frame’s title.
79 80 81 |
# File 'lib/ferrum/frame.rb', line 79 def title evaluate("document.title") end |
#url ⇒ String
Returns current frame’s ‘location.href`.
65 66 67 |
# File 'lib/ferrum/frame.rb', line 65 def url evaluate("document.location.href") end |