Class: Puppeteer::Frame
- Inherits:
-
Object
- Object
- Puppeteer::Frame
- Defined in:
- lib/puppeteer/frame.rb,
sig/_supplementary.rbs,
sig/puppeteer/frame.rbs
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) ⇒ Boolean
- #_child_frames ⇒ Object
- #_client ⇒ Puppeteer::CDPSession
- #accessibility ⇒ Puppeteer::Accessibility
- #add_script_tag(url: nil, path: nil, content: nil, type: nil, id: nil) ⇒ Puppeteer::ElementHandle
- #add_style_tag(url: nil, path: nil, content: nil) ⇒ Puppeteer::ElementHandle
- #child_frames ⇒ Array[Puppeteer::Frame]
- #click(selector, delay: nil, button: nil, count: nil) ⇒ void
- #content ⇒ String
- #default_timeout ⇒ Numeric
- #detach ⇒ void
- #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) ⇒ Puppeteer::JSHandle
- #execution_context ⇒ Puppeteer::ExecutionContext
- #extension_realms ⇒ Array[untyped]
- #focus(selector) ⇒ void
- #frame_element ⇒ Puppeteer::ElementHandle?
- #goto(url, referer: nil, referrer_policy: nil, timeout: nil, wait_until: nil) ⇒ Puppeteer::HTTPResponse?
- #handle_lifecycle_event(loader_id, name) ⇒ void
- #handle_loading_started ⇒ void
- #handle_loading_stopped ⇒ void
- #has_started_loading? ⇒ Boolean
- #hover(selector) ⇒ void
-
#initialize(frame_manager, parent_frame, frame_id, client) ⇒ Frame
constructor
A new instance of Frame.
- #inspect ⇒ String
- #locator(selector_or_function) ⇒ Puppeteer::Locator
- #name ⇒ String
- #navigated(frame_payload) ⇒ void
- #navigated_within_document(url) ⇒ void
- #oop_frame? ⇒ Boolean
- #page ⇒ Puppeteer::Page
- #parent_frame ⇒ Puppeteer::Frame?
-
#query_selector(selector) ⇒ Puppeteer::ElementHandle?
(also: #S)
$()in JavaScript. -
#query_selector_all(selector, isolate: nil) ⇒ Array[Puppeteer::ElementHandle]
(also: #SS)
$$()in JavaScript. - #select(selector, *values) ⇒ Array[String]
- #set_content(html, timeout: nil, wait_until: nil) ⇒ void
-
#Sx(expression) ⇒ Array[Puppeteer::ElementHandle]
$x()in JavaScript. - #tap(selector) ⇒ void
- #title ⇒ String
- #type_text(selector, text, delay: nil) ⇒ void
- #url ⇒ String?
- #wait_for_function(page_function, args: [], polling: nil, timeout: nil) ⇒ Puppeteer::JSHandle
- #wait_for_navigation(timeout: nil, wait_until: nil, ignore_same_document_navigation: false) ⇒ Puppeteer::HTTPResponse?
- #wait_for_selector(selector, visible: nil, hidden: nil, timeout: nil) ⇒ Puppeteer::ElementHandle?
- #wait_for_timeout(milliseconds) ⇒ void
- #wait_for_xpath(xpath, visible: nil, hidden: nil, timeout: nil) ⇒ Puppeteer::ElementHandle?
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.
81 82 83 |
# File 'lib/puppeteer/frame.rb', line 81 def client @client end |
#extension_worlds ⇒ Object
Returns the value of attribute extension_worlds.
80 81 82 |
# File 'lib/puppeteer/frame.rb', line 80 def extension_worlds @extension_worlds end |
#frame_manager ⇒ Object
Returns the value of attribute frame_manager.
80 81 82 |
# File 'lib/puppeteer/frame.rb', line 80 def frame_manager @frame_manager end |
#id ⇒ Object
Returns the value of attribute id.
80 81 82 |
# File 'lib/puppeteer/frame.rb', line 80 def id @id end |
#lifecycle_events ⇒ Object
Returns the value of attribute lifecycle_events.
80 81 82 |
# File 'lib/puppeteer/frame.rb', line 80 def lifecycle_events @lifecycle_events end |
#loader_id ⇒ Object
Returns the value of attribute loader_id.
80 81 82 |
# File 'lib/puppeteer/frame.rb', line 80 def loader_id @loader_id end |
#main_world ⇒ Object
Returns the value of attribute main_world.
80 81 82 |
# File 'lib/puppeteer/frame.rb', line 80 def main_world @main_world end |
#puppeteer_world ⇒ Object
Returns the value of attribute puppeteer_world.
80 81 82 |
# File 'lib/puppeteer/frame.rb', line 80 def puppeteer_world @puppeteer_world end |
Instance Method Details
#==(other) ⇒ Boolean
85 86 87 88 89 90 91 92 |
# File 'lib/puppeteer/frame.rb', line 85 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 |
#_child_frames ⇒ Object
257 258 259 |
# File 'lib/puppeteer/frame.rb', line 257 protected def _child_frames @child_frames end |
#_client ⇒ Puppeteer::CDPSession
40 41 42 |
# File 'lib/puppeteer/frame.rb', line 40 def _client @client end |
#accessibility ⇒ Puppeteer::Accessibility
56 57 58 |
# File 'lib/puppeteer/frame.rb', line 56 def accessibility @accessibility ||= Puppeteer::Accessibility.new(self) end |
#add_script_tag(url: nil, path: nil, content: nil, type: nil, id: nil) ⇒ Puppeteer::ElementHandle
277 278 279 |
# File 'lib/puppeteer/frame.rb', line 277 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) ⇒ Puppeteer::ElementHandle
285 286 287 |
# File 'lib/puppeteer/frame.rb', line 285 def add_style_tag(url: nil, path: nil, content: nil) @main_world.add_style_tag(url: url, path: path, content: content) end |
#child_frames ⇒ Array[Puppeteer::Frame]
262 263 264 |
# File 'lib/puppeteer/frame.rb', line 262 def child_frames @child_frames.to_a end |
#click(selector, delay: nil, button: nil, count: nil) ⇒ void
This method returns an undefined value.
294 295 296 |
# File 'lib/puppeteer/frame.rb', line 294 def click(selector, delay: nil, button: nil, count: nil) @puppeteer_world.click(selector, delay: delay, button: , count: count) end |
#content ⇒ String
216 217 218 |
# File 'lib/puppeteer/frame.rb', line 216 def content @puppeteer_world.content end |
#default_timeout ⇒ Numeric
61 62 63 |
# File 'lib/puppeteer/frame.rb', line 61 def default_timeout @frame_manager.timeout_settings.timeout end |
#detach ⇒ void
This method returns an undefined value.
434 435 436 437 438 439 440 441 442 443 |
# File 'lib/puppeteer/frame.rb', line 434 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
267 268 269 |
# File 'lib/puppeteer/frame.rb', line 267 def detached? @detached end |
#eval_on_selector(selector, page_function, *args) ⇒ Object Also known as: Seval
$eval() in JavaScript.
185 186 187 |
# File 'lib/puppeteer/frame.rb', line 185 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.
197 198 199 |
# File 'lib/puppeteer/frame.rb', line 197 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
148 149 150 |
# File 'lib/puppeteer/frame.rb', line 148 def evaluate(page_function, *args) @main_world.evaluate(page_function, *args) end |
#evaluate_handle(page_function, *args) ⇒ Puppeteer::JSHandle
139 140 141 |
# File 'lib/puppeteer/frame.rb', line 139 def evaluate_handle(page_function, *args) @main_world.evaluate_handle(page_function, *args) end |
#execution_context ⇒ Puppeteer::ExecutionContext
132 133 134 |
# File 'lib/puppeteer/frame.rb', line 132 def execution_context @main_world.execution_context end |
#extension_realms ⇒ Array[untyped]
239 240 241 |
# File 'lib/puppeteer/frame.rb', line 239 def extension_realms @extension_worlds.values end |
#focus(selector) ⇒ void
This method returns an undefined value.
302 303 304 |
# File 'lib/puppeteer/frame.rb', line 302 def focus(selector) @puppeteer_world.focus(selector) end |
#frame_element ⇒ Puppeteer::ElementHandle?
249 250 251 252 253 254 255 |
# File 'lib/puppeteer/frame.rb', line 249 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) ⇒ Puppeteer::HTTPResponse?
105 106 107 108 109 110 111 112 113 114 |
# File 'lib/puppeteer/frame.rb', line 105 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) ⇒ void
This method returns an undefined value.
414 415 416 417 418 419 420 |
# File 'lib/puppeteer/frame.rb', line 414 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 ⇒ void
This method returns an undefined value.
423 424 425 |
# File 'lib/puppeteer/frame.rb', line 423 def handle_loading_started @has_started_loading = true end |
#handle_loading_stopped ⇒ void
This method returns an undefined value.
428 429 430 431 |
# File 'lib/puppeteer/frame.rb', line 428 def handle_loading_stopped @lifecycle_events << 'DOMContentLoaded' @lifecycle_events << 'load' end |
#has_started_loading? ⇒ Boolean
95 96 97 |
# File 'lib/puppeteer/frame.rb', line 95 def has_started_loading? @has_started_loading end |
#hover(selector) ⇒ void
This method returns an undefined value.
310 311 312 |
# File 'lib/puppeteer/frame.rb', line 310 def hover(selector) @puppeteer_world.hover(selector) end |
#inspect ⇒ String
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) ⇒ Puppeteer::Locator
67 68 69 70 71 72 73 |
# File 'lib/puppeteer/frame.rb', line 67 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 ⇒ String
229 230 231 |
# File 'lib/puppeteer/frame.rb', line 229 def name @name || '' end |
#navigated(frame_payload) ⇒ void
This method returns an undefined value.
400 401 402 403 |
# File 'lib/puppeteer/frame.rb', line 400 def navigated(frame_payload) @name = frame_payload['name'] @url = "#{frame_payload['url']}#{frame_payload['urlFragment']}" end |
#navigated_within_document(url) ⇒ void
This method returns an undefined value.
407 408 409 |
# File 'lib/puppeteer/frame.rb', line 407 def navigated_within_document(url) @url = url end |
#oop_frame? ⇒ Boolean
76 77 78 |
# File 'lib/puppeteer/frame.rb', line 76 def oop_frame? @client != @frame_manager.client end |
#page ⇒ Puppeteer::Page
51 52 53 |
# File 'lib/puppeteer/frame.rb', line 51 def page @frame_manager.page end |
#parent_frame ⇒ Puppeteer::Frame?
244 245 246 |
# File 'lib/puppeteer/frame.rb', line 244 def parent_frame @parent_frame end |
#query_selector(selector) ⇒ Puppeteer::ElementHandle? Also known as: S
$() in JavaScript.
157 158 159 |
# File 'lib/puppeteer/frame.rb', line 157 def query_selector(selector) @main_world.query_selector(selector) end |
#query_selector_all(selector, isolate: nil) ⇒ Array[Puppeteer::ElementHandle] Also known as: SS
$$() in JavaScript.
208 209 210 |
# File 'lib/puppeteer/frame.rb', line 208 def query_selector_all(selector, isolate: nil) @main_world.query_selector_all(selector, isolate: isolate) end |
#select(selector, *values) ⇒ Array[String]
317 318 319 |
# File 'lib/puppeteer/frame.rb', line 317 def select(selector, *values) @puppeteer_world.select(selector, *values) end |
#set_content(html, timeout: nil, wait_until: nil) ⇒ void
This method returns an undefined value.
224 225 226 |
# File 'lib/puppeteer/frame.rb', line 224 def set_content(html, timeout: nil, wait_until: nil) @puppeteer_world.set_content(html, timeout: timeout, wait_until: wait_until) end |
#Sx(expression) ⇒ Array[Puppeteer::ElementHandle]
$x() in JavaScript. $ is not allowed to use as a method name in Ruby.
167 168 169 170 171 172 173 174 175 176 |
# File 'lib/puppeteer/frame.rb', line 167 def Sx(expression) param_xpath = if expression.start_with?('//') ".#{expression}" else expression end query_selector_all("xpath/#{param_xpath}") end |
#tap(selector) ⇒ void
This method returns an undefined value.
325 326 327 |
# File 'lib/puppeteer/frame.rb', line 325 def tap(selector) @puppeteer_world.tap(selector) end |
#title ⇒ String
394 395 396 |
# File 'lib/puppeteer/frame.rb', line 394 def title @puppeteer_world.title end |
#type_text(selector, text, delay: nil) ⇒ void
This method returns an undefined value.
335 336 337 |
# File 'lib/puppeteer/frame.rb', line 335 def type_text(selector, text, delay: nil) @main_world.type_text(selector, text, delay: delay) end |
#url ⇒ String?
234 235 236 |
# File 'lib/puppeteer/frame.rb', line 234 def url @url end |
#wait_for_function(page_function, args: [], polling: nil, timeout: nil) ⇒ Puppeteer::JSHandle
387 388 389 |
# File 'lib/puppeteer/frame.rb', line 387 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) ⇒ Puppeteer::HTTPResponse?
120 121 122 123 124 125 126 127 |
# File 'lib/puppeteer/frame.rb', line 120 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) ⇒ Puppeteer::ElementHandle?
346 347 348 349 350 351 352 353 354 |
# File 'lib/puppeteer/frame.rb', line 346 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) ⇒ void
This method returns an undefined value.
360 361 362 |
# File 'lib/puppeteer/frame.rb', line 360 def wait_for_timeout(milliseconds) Puppeteer::AsyncUtils.sleep_seconds(milliseconds / 1000.0) end |
#wait_for_xpath(xpath, visible: nil, hidden: nil, timeout: nil) ⇒ Puppeteer::ElementHandle?
369 370 371 372 373 374 375 376 377 378 |
# File 'lib/puppeteer/frame.rb', line 369 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 |