Class: Puppeteer::DOMWorld
- Inherits:
-
Object
- Object
- Puppeteer::DOMWorld
- Defined in:
- lib/puppeteer/dom_world.rb
Overview
Defined Under Namespace
Classes: DetachedError, DocumentEvaluationError
Instance Attribute Summary collapse
-
#frame ⇒ Object
readonly
Returns the value of attribute frame.
Instance Method Summary collapse
- #click(selector, delay: nil, button: nil, click_count: nil) ⇒ Object
- #context=(context) ⇒ Object
- #delete_context(execution_context_id) ⇒ Object
- #detach ⇒ Object
- #evaluate(page_function, *args) ⇒ !Promise<*>
- #evaluate_handle(page_function, *args) ⇒ !Promise<!Puppeteer.JSHandle>
- #execution_context ⇒ !Promise<!Puppeteer.ExecutionContext>
- #has_context? ⇒ Boolean
-
#initialize(frame_manager, frame, timeout_settings) ⇒ DOMWorld
constructor
A new instance of DOMWorld.
-
#S(selector) ⇒ !Promise<?Puppeteer.ElementHandle>
`$()` in JavaScript.
-
#Seval(selector, page_function, *args) ⇒ !Promise<(!Object|undefined)>
`$eval()` in JavaScript.
-
#SS(selector) ⇒ !Promise<!Array<!Puppeteer.ElementHandle>>
`$$()` in JavaScript.
-
#SSeval(selector, page_function, *args) ⇒ !Promise<(!Object|undefined)>
`$$eval()` in JavaScript.
-
#Sx(expression) ⇒ !Promise<!Array<!Puppeteer.ElementHandle>>
`$x()` in JavaScript.
Constructor Details
#initialize(frame_manager, frame, timeout_settings) ⇒ DOMWorld
Returns a new instance of DOMWorld.
10 11 12 13 14 15 16 17 18 |
# File 'lib/puppeteer/dom_world.rb', line 10 def initialize(frame_manager, frame, timeout_settings) @frame_manager = frame_manager @frame = frame @timeout_settings = timeout_settings @context_promise = resolvable_future @pending_destroy = [] @wait_tasks = Set.new @detached = false end |
Instance Attribute Details
#frame ⇒ Object (readonly)
Returns the value of attribute frame.
20 21 22 |
# File 'lib/puppeteer/dom_world.rb', line 20 def frame @frame end |
Instance Method Details
#click(selector, delay: nil, button: nil, click_count: nil) ⇒ Object
328 329 330 331 332 |
# File 'lib/puppeteer/dom_world.rb', line 328 def click(selector, delay: nil, button: nil, click_count: nil) handle = S(selector) handle.click(delay: delay, button: , click_count: click_count) handle.dispose end |
#context=(context) ⇒ Object
23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 |
# File 'lib/puppeteer/dom_world.rb', line 23 def context=(context) # D, [2020-04-12T22:45:03.938754 #46154] DEBUG -- : RECV << {"method"=>"Runtime.executionContextCreated", "params"=>{"context"=>{"id"=>3, "origin"=>"https://github.com", "name"=>"", "auxData"=>{"isDefault"=>true, "type"=>"default", "frameId"=>"3AD7F1E82BCBA88BFE31D03BC49FF6CB"}}}, "sessionId"=>"636CEF0C4FEAFC4FE815E9E7B5F7BA68"} # D, [2020-04-12T22:45:03.938856 #46154] DEBUG -- : RECV << {"method"=>"Runtime.executionContextCreated", "params"=>{"context"=>{"id"=>4, "origin"=>"://", "name"=>"__puppeteer_utility_world__", "auxData"=>{"isDefault"=>false, "type"=>"isolated", "frameId"=>"3AD7F1E82BCBA88BFE31D03BC49FF6CB"}}}, "sessionId"=>"636CEF0C4FEAFC4FE815E9E7B5F7BA68"} # D, [2020-04-12T22:45:03.938960 #46154] DEBUG -- : RECV << {"method"=>"Runtime.executionContextDestroyed", "params"=>{"executionContextId"=>1}, "sessionId"=>"636CEF0C4FEAFC4FE815E9E7B5F7BA68"} # D, [2020-04-12T22:45:03.939110 #46154] DEBUG -- : RECV << {"method"=>"Page.frameNavigated", "params"=>{"frame"=>{"id"=>"3AD7F1E82BCBA88BFE31D03BC49FF6CB", "loaderId"=>"301B349884E582986C502CBE020966DF", "url"=>"https://github.com/", "securityOrigin"=>"https://github.com", "mimeType"=>"text/html"}}, "sessionId"=>"636CEF0C4FEAFC4FE815E9E7B5F7BA68"} # D, [2020-04-12T22:45:03.939793 #46154] DEBUG -- : RECV << {"method"=>"Runtime.executionContextDestroyed", "params"=>{"executionContextId"=>2}, "sessionId"=>"636CEF0C4FEAFC4FE815E9E7B5F7BA68"} # executionContextDestroyed is often notified after executionContextCreated. if context if @context_promise.fulfilled? @pending_destroy << context._context_id @document = nil @context_promise = resolvable_future end @context_promise.fulfill(context) # for (const waitTask of this._waitTasks) # waitTask.rerun(); else raise ArgumentError.new("context should now be nil. Use #delete_context for clearing document.") end end |
#delete_context(execution_context_id) ⇒ Object
45 46 47 48 49 50 51 52 |
# File 'lib/puppeteer/dom_world.rb', line 45 def delete_context(execution_context_id) if @pending_destroy.include?(execution_context_id) @pending_destroy.delete(execution_context_id) else @document = nil @context_promise = resolvable_future end end |
#detach ⇒ Object
58 59 60 61 62 63 |
# File 'lib/puppeteer/dom_world.rb', line 58 def detach @detached = true @wait_tasks.each do |wait_task| wait_task.terminate(Puppeteer::WaitTask::TerminatedError.new('waitForFunction failed: frame got detached.')) end end |
#evaluate(page_function, *args) ⇒ !Promise<*>
85 86 87 |
# File 'lib/puppeteer/dom_world.rb', line 85 def evaluate(page_function, *args) execution_context.evaluate(page_function, *args) end |
#evaluate_handle(page_function, *args) ⇒ !Promise<!Puppeteer.JSHandle>
78 79 80 |
# File 'lib/puppeteer/dom_world.rb', line 78 def evaluate_handle(page_function, *args) execution_context.evaluate_handle(page_function, *args) end |
#execution_context ⇒ !Promise<!Puppeteer.ExecutionContext>
68 69 70 71 72 73 |
# File 'lib/puppeteer/dom_world.rb', line 68 def execution_context if @detached raise DetachedError.new("Execution Context is not available in detached frame \"#{@frame.url}\" (are you trying to evaluate?)") end @context_promise.value! end |
#has_context? ⇒ Boolean
54 55 56 |
# File 'lib/puppeteer/dom_world.rb', line 54 def has_context? @context_promise.resolved? end |
#S(selector) ⇒ !Promise<?Puppeteer.ElementHandle>
`$()` in JavaScript. $ is not allowed to use as a method name in Ruby.
92 93 94 |
# File 'lib/puppeteer/dom_world.rb', line 92 def S(selector) document.S(selector) end |
#Seval(selector, page_function, *args) ⇒ !Promise<(!Object|undefined)>
`$eval()` in JavaScript. $ is not allowed to use as a method name in Ruby.
125 126 127 |
# File 'lib/puppeteer/dom_world.rb', line 125 def Seval(selector, page_function, *args) document.Seval(selector, page_function, *args) end |
#SS(selector) ⇒ !Promise<!Array<!Puppeteer.ElementHandle>>
`$$()` in JavaScript. $ is not allowed to use as a method name in Ruby.
141 142 143 |
# File 'lib/puppeteer/dom_world.rb', line 141 def SS(selector) document.SS(selector) end |
#SSeval(selector, page_function, *args) ⇒ !Promise<(!Object|undefined)>
`$$eval()` in JavaScript. $ is not allowed to use as a method name in Ruby.
134 135 136 |
# File 'lib/puppeteer/dom_world.rb', line 134 def SSeval(selector, page_function, *args) document.SSeval(selector, page_function, *args) end |
#Sx(expression) ⇒ !Promise<!Array<!Puppeteer.ElementHandle>>
`$x()` in JavaScript. $ is not allowed to use as a method name in Ruby.
116 117 118 |
# File 'lib/puppeteer/dom_world.rb', line 116 def Sx(expression) document.Sx(expression) end |