Class: Puppeteer::Frame
- Inherits:
-
Object
- Object
- Puppeteer::Frame
- Defined in:
- lib/puppeteer/frame.rb
Overview
rbs_inline: enabled
Instance Attribute Summary collapse
-
#client ⇒ Object
readonly
Returns the value of attribute client.
-
#extension_worlds ⇒ Object
Returns the value of attribute extension_worlds.
-
#frame_manager ⇒ Object
Returns the value of attribute frame_manager.
-
#id ⇒ Object
Returns the value of attribute id.
-
#lifecycle_events ⇒ Object
Returns the value of attribute lifecycle_events.
-
#loader_id ⇒ Object
Returns the value of attribute loader_id.
-
#main_world ⇒ Object
Returns the value of attribute main_world.
-
#puppeteer_world ⇒ Object
Returns the value of attribute puppeteer_world.
Instance Method Summary collapse
- #==(other) ⇒ Object
- #_client ⇒ Object
- #add_script_tag(url: nil, path: nil, content: nil, type: nil, id: nil) ⇒ Object
- #add_style_tag(url: nil, path: nil, content: nil) ⇒ Object
- #child_frames ⇒ Object
- #click(selector, delay: nil, button: nil, click_count: nil, count: nil) ⇒ Object
- #content ⇒ Object
- #default_timeout ⇒ Object
- #detach ⇒ Object
- #detached? ⇒ Boolean
-
#eval_on_selector(selector, page_function, *args) ⇒ Object
(also: #Seval)
‘$eval()` in JavaScript.
-
#eval_on_selector_all(selector, page_function, *args) ⇒ Object
(also: #SSeval)
‘$$eval()` in JavaScript.
- #evaluate(page_function, *args) ⇒ Object
- #evaluate_handle(page_function, *args) ⇒ Object
- #execution_context ⇒ Object
- #extension_realms ⇒ Object
- #focus(selector) ⇒ Object
- #frame_element ⇒ Object
- #goto(url, referer: nil, referrer_policy: nil, timeout: nil, wait_until: nil) ⇒ Object
- #handle_lifecycle_event(loader_id, name) ⇒ Object
- #handle_loading_started ⇒ Object
- #handle_loading_stopped ⇒ Object
- #has_started_loading? ⇒ Boolean
- #hover(selector) ⇒ Object
-
#initialize(frame_manager, parent_frame, frame_id, client) ⇒ Frame
constructor
A new instance of Frame.
- #inspect ⇒ Object
- #locator(selector_or_function) ⇒ Object
- #name ⇒ Object
- #navigated(frame_payload) ⇒ Object
- #navigated_within_document(url) ⇒ Object
- #oop_frame? ⇒ Boolean
- #page ⇒ Object
- #parent_frame ⇒ Object
-
#query_selector(selector) ⇒ Object
(also: #S)
‘$()` in JavaScript.
-
#query_selector_all(selector, isolate: nil) ⇒ Object
(also: #SS)
‘$$()` in JavaScript.
- #select(selector, *values) ⇒ Object
- #set_content(html, timeout: nil, wait_until: nil) ⇒ Object
-
#Sx(expression) ⇒ Object
‘$x()` in JavaScript.
- #tap(selector) ⇒ Object
- #title ⇒ Object
- #type_text(selector, text, delay: nil) ⇒ Object
- #url ⇒ Object
- #wait_for_function(page_function, args: [], polling: nil, timeout: nil) ⇒ Object
- #wait_for_navigation(timeout: nil, wait_until: nil, ignore_same_document_navigation: false) ⇒ Object
- #wait_for_selector(selector, visible: nil, hidden: nil, timeout: nil) ⇒ Object
- #wait_for_timeout(milliseconds) ⇒ Object
- #wait_for_xpath(xpath, visible: nil, hidden: nil, timeout: nil) ⇒ Object
Constructor Details
#initialize(frame_manager, parent_frame, frame_id, client) ⇒ Frame
Returns a new instance of Frame.
11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 |
# File 'lib/puppeteer/frame.rb', line 11 def initialize(frame_manager, parent_frame, frame_id, client) @frame_manager = frame_manager @parent_frame = parent_frame @id = frame_id @detached = false @has_started_loading = false @loader_id = '' @url = 'about:blank' @lifecycle_events = Set.new @child_frames = Set.new @extension_worlds = {} if parent_frame parent_frame._child_frames << self end update_client(client) end |
Instance Attribute Details
#client ⇒ Object (readonly)
Returns the value of attribute client.
76 77 78 |
# File 'lib/puppeteer/frame.rb', line 76 def client @client end |
#extension_worlds ⇒ Object
Returns the value of attribute extension_worlds.
75 76 77 |
# File 'lib/puppeteer/frame.rb', line 75 def extension_worlds @extension_worlds end |
#frame_manager ⇒ Object
Returns the value of attribute frame_manager.
75 76 77 |
# File 'lib/puppeteer/frame.rb', line 75 def frame_manager @frame_manager end |
#id ⇒ Object
Returns the value of attribute id.
75 76 77 |
# File 'lib/puppeteer/frame.rb', line 75 def id @id end |
#lifecycle_events ⇒ Object
Returns the value of attribute lifecycle_events.
75 76 77 |
# File 'lib/puppeteer/frame.rb', line 75 def lifecycle_events @lifecycle_events end |
#loader_id ⇒ Object
Returns the value of attribute loader_id.
75 76 77 |
# File 'lib/puppeteer/frame.rb', line 75 def loader_id @loader_id end |
#main_world ⇒ Object
Returns the value of attribute main_world.
75 76 77 |
# File 'lib/puppeteer/frame.rb', line 75 def main_world @main_world end |
#puppeteer_world ⇒ Object
Returns the value of attribute puppeteer_world.
75 76 77 |
# File 'lib/puppeteer/frame.rb', line 75 def puppeteer_world @puppeteer_world end |
Instance Method Details
#==(other) ⇒ Object
80 81 82 83 84 85 86 87 |
# File 'lib/puppeteer/frame.rb', line 80 def ==(other) other = other.__getobj__ if other.is_a?(Puppeteer::ReactorRunner::Proxy) return true if equal?(other) return false unless other.is_a?(Puppeteer::Frame) return false unless @id && other.id @id == other.id end |
#_client ⇒ Object
40 41 42 |
# File 'lib/puppeteer/frame.rb', line 40 def _client @client end |
#add_script_tag(url: nil, path: nil, content: nil, type: nil, id: nil) ⇒ Object
272 273 274 |
# File 'lib/puppeteer/frame.rb', line 272 def add_script_tag(url: nil, path: nil, content: nil, type: nil, id: nil) @main_world.add_script_tag(url: url, path: path, content: content, type: type, id: id) end |
#add_style_tag(url: nil, path: nil, content: nil) ⇒ Object
280 281 282 |
# File 'lib/puppeteer/frame.rb', line 280 def add_style_tag(url: nil, path: nil, content: nil) @main_world.add_style_tag(url: url, path: path, content: content) end |
#child_frames ⇒ Object
257 258 259 |
# File 'lib/puppeteer/frame.rb', line 257 def child_frames @child_frames.to_a end |
#click(selector, delay: nil, button: nil, click_count: nil, count: nil) ⇒ Object
290 291 292 |
# File 'lib/puppeteer/frame.rb', line 290 def click(selector, delay: nil, button: nil, click_count: nil, count: nil) @puppeteer_world.click(selector, delay: delay, button: , click_count: click_count, count: count) end |
#content ⇒ Object
211 212 213 |
# File 'lib/puppeteer/frame.rb', line 211 def content @puppeteer_world.content end |
#default_timeout ⇒ Object
56 57 58 |
# File 'lib/puppeteer/frame.rb', line 56 def default_timeout @frame_manager.timeout_settings.timeout end |
#detach ⇒ Object
430 431 432 433 434 435 436 437 438 439 |
# File 'lib/puppeteer/frame.rb', line 430 def detach @detached = true @main_world.detach @puppeteer_world.detach @extension_worlds.each_value(&:detach) if @parent_frame @parent_frame._child_frames.delete(self) end @parent_frame = nil end |
#detached? ⇒ Boolean
262 263 264 |
# File 'lib/puppeteer/frame.rb', line 262 def detached? @detached end |
#eval_on_selector(selector, page_function, *args) ⇒ Object Also known as: Seval
‘$eval()` in JavaScript.
180 181 182 |
# File 'lib/puppeteer/frame.rb', line 180 def eval_on_selector(selector, page_function, *args) @main_world.eval_on_selector(selector, page_function, *args) end |
#eval_on_selector_all(selector, page_function, *args) ⇒ Object Also known as: SSeval
‘$$eval()` in JavaScript.
192 193 194 |
# File 'lib/puppeteer/frame.rb', line 192 def eval_on_selector_all(selector, page_function, *args) @main_world.eval_on_selector_all(selector, page_function, *args) end |
#evaluate(page_function, *args) ⇒ Object
143 144 145 |
# File 'lib/puppeteer/frame.rb', line 143 def evaluate(page_function, *args) @main_world.evaluate(page_function, *args) end |
#evaluate_handle(page_function, *args) ⇒ Object
134 135 136 |
# File 'lib/puppeteer/frame.rb', line 134 def evaluate_handle(page_function, *args) @main_world.evaluate_handle(page_function, *args) end |
#execution_context ⇒ Object
127 128 129 |
# File 'lib/puppeteer/frame.rb', line 127 def execution_context @main_world.execution_context end |
#extension_realms ⇒ Object
234 235 236 |
# File 'lib/puppeteer/frame.rb', line 234 def extension_realms @extension_worlds.values end |
#focus(selector) ⇒ Object
298 299 300 |
# File 'lib/puppeteer/frame.rb', line 298 def focus(selector) @puppeteer_world.focus(selector) end |
#frame_element ⇒ Object
244 245 246 247 248 249 250 |
# File 'lib/puppeteer/frame.rb', line 244 def frame_element parent = parent_frame return nil unless parent response = parent.client.('DOM.getFrameOwner', frameId: @id) parent.main_world.adopt_backend_node(response['backendNodeId']) end |
#goto(url, referer: nil, referrer_policy: nil, timeout: nil, wait_until: nil) ⇒ Object
100 101 102 103 104 105 106 107 108 109 |
# File 'lib/puppeteer/frame.rb', line 100 def goto(url, referer: nil, referrer_policy: nil, timeout: nil, wait_until: nil) @frame_manager.navigate_frame( self, url, referer: referer, referrer_policy: referrer_policy, timeout: timeout, wait_until: wait_until, ) end |
#handle_lifecycle_event(loader_id, name) ⇒ Object
410 411 412 413 414 415 416 |
# File 'lib/puppeteer/frame.rb', line 410 def handle_lifecycle_event(loader_id, name) if name == 'init' @loader_id = loader_id @lifecycle_events.clear end @lifecycle_events << name end |
#handle_loading_started ⇒ Object
419 420 421 |
# File 'lib/puppeteer/frame.rb', line 419 def handle_loading_started @has_started_loading = true end |
#handle_loading_stopped ⇒ Object
424 425 426 427 |
# File 'lib/puppeteer/frame.rb', line 424 def handle_loading_stopped @lifecycle_events << 'DOMContentLoaded' @lifecycle_events << 'load' end |
#has_started_loading? ⇒ Boolean
90 91 92 |
# File 'lib/puppeteer/frame.rb', line 90 def has_started_loading? @has_started_loading end |
#hover(selector) ⇒ Object
306 307 308 |
# File 'lib/puppeteer/frame.rb', line 306 def hover(selector) @puppeteer_world.hover(selector) end |
#inspect ⇒ Object
31 32 33 34 35 36 37 |
# File 'lib/puppeteer/frame.rb', line 31 def inspect values = %i[id parent_frame detached loader_id lifecycle_events child_frames].map do |sym| value = instance_variable_get(:"@#{sym}") "@#{sym}=#{value}" end "#<Puppeteer::Frame #{values.join(' ')}>" end |
#locator(selector_or_function) ⇒ Object
62 63 64 65 66 67 68 |
# File 'lib/puppeteer/frame.rb', line 62 def locator(selector_or_function) if Puppeteer::Locator.function_string?(selector_or_function) Puppeteer::FunctionLocator.create(self, selector_or_function) else Puppeteer::NodeLocator.create(self, selector_or_function) end end |
#name ⇒ Object
224 225 226 |
# File 'lib/puppeteer/frame.rb', line 224 def name @name || '' end |
#navigated(frame_payload) ⇒ Object
396 397 398 399 |
# File 'lib/puppeteer/frame.rb', line 396 def navigated(frame_payload) @name = frame_payload['name'] @url = "#{frame_payload['url']}#{frame_payload['urlFragment']}" end |
#navigated_within_document(url) ⇒ Object
403 404 405 |
# File 'lib/puppeteer/frame.rb', line 403 def navigated_within_document(url) @url = url end |
#oop_frame? ⇒ Boolean
71 72 73 |
# File 'lib/puppeteer/frame.rb', line 71 def oop_frame? @client != @frame_manager.client end |
#page ⇒ Object
51 52 53 |
# File 'lib/puppeteer/frame.rb', line 51 def page @frame_manager.page end |
#parent_frame ⇒ Object
239 240 241 |
# File 'lib/puppeteer/frame.rb', line 239 def parent_frame @parent_frame end |
#query_selector(selector) ⇒ Object Also known as: S
‘$()` in JavaScript.
152 153 154 |
# File 'lib/puppeteer/frame.rb', line 152 def query_selector(selector) @main_world.query_selector(selector) end |
#query_selector_all(selector, isolate: nil) ⇒ Object Also known as: SS
‘$$()` in JavaScript.
203 204 205 |
# File 'lib/puppeteer/frame.rb', line 203 def query_selector_all(selector, isolate: nil) @main_world.query_selector_all(selector, isolate: isolate) end |
#select(selector, *values) ⇒ Object
313 314 315 |
# File 'lib/puppeteer/frame.rb', line 313 def select(selector, *values) @puppeteer_world.select(selector, *values) end |
#set_content(html, timeout: nil, wait_until: nil) ⇒ Object
219 220 221 |
# File 'lib/puppeteer/frame.rb', line 219 def set_content(html, timeout: nil, wait_until: nil) @puppeteer_world.set_content(html, timeout: timeout, wait_until: wait_until) end |
#Sx(expression) ⇒ Object
‘$x()` in JavaScript. $ is not allowed to use as a method name in Ruby.
162 163 164 165 166 167 168 169 170 171 |
# File 'lib/puppeteer/frame.rb', line 162 def Sx(expression) param_xpath = if expression.start_with?('//') ".#{expression}" else expression end query_selector_all("xpath/#{param_xpath}") end |
#tap(selector) ⇒ Object
321 322 323 |
# File 'lib/puppeteer/frame.rb', line 321 def tap(selector) @puppeteer_world.tap(selector) end |
#title ⇒ Object
390 391 392 |
# File 'lib/puppeteer/frame.rb', line 390 def title @puppeteer_world.title end |
#type_text(selector, text, delay: nil) ⇒ Object
331 332 333 |
# File 'lib/puppeteer/frame.rb', line 331 def type_text(selector, text, delay: nil) @main_world.type_text(selector, text, delay: delay) end |
#url ⇒ Object
229 230 231 |
# File 'lib/puppeteer/frame.rb', line 229 def url @url end |
#wait_for_function(page_function, args: [], polling: nil, timeout: nil) ⇒ Object
383 384 385 |
# File 'lib/puppeteer/frame.rb', line 383 def wait_for_function(page_function, args: [], polling: nil, timeout: nil) @main_world.wait_for_function(page_function, args: args, polling: polling, timeout: timeout) end |
#wait_for_navigation(timeout: nil, wait_until: nil, ignore_same_document_navigation: false) ⇒ Object
115 116 117 118 119 120 121 122 |
# File 'lib/puppeteer/frame.rb', line 115 def (timeout: nil, wait_until: nil, ignore_same_document_navigation: false) @frame_manager.( self, timeout: timeout, wait_until: wait_until, ignore_same_document_navigation: , ) end |
#wait_for_selector(selector, visible: nil, hidden: nil, timeout: nil) ⇒ Object
342 343 344 345 346 347 348 349 350 |
# File 'lib/puppeteer/frame.rb', line 342 def wait_for_selector(selector, visible: nil, hidden: nil, timeout: nil) query_handler_manager = Puppeteer::QueryHandlerManager.instance query_handler_manager.detect_query_handler(selector).wait_for( self, visible: visible, hidden: hidden, timeout: timeout, ) end |
#wait_for_timeout(milliseconds) ⇒ Object
356 357 358 |
# File 'lib/puppeteer/frame.rb', line 356 def wait_for_timeout(milliseconds) Puppeteer::AsyncUtils.sleep_seconds(milliseconds / 1000.0) end |
#wait_for_xpath(xpath, visible: nil, hidden: nil, timeout: nil) ⇒ Object
365 366 367 368 369 370 371 372 373 374 |
# File 'lib/puppeteer/frame.rb', line 365 def wait_for_xpath(xpath, visible: nil, hidden: nil, timeout: nil) param_xpath = if xpath.start_with?('//') ".#{xpath}" else xpath end wait_for_selector("xpath/#{param_xpath}", visible: visible, hidden: hidden, timeout: timeout) end |