Class: Puppeteer::Frame

Inherits:
Object
  • Object
show all
Defined in:
lib/puppeteer/frame.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(frame_manager, client, parent_frame, frame_id) ⇒ Frame

Returns a new instance of Frame.

Parameters:



6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
# File 'lib/puppeteer/frame.rb', line 6

def initialize(frame_manager, client, parent_frame, frame_id)
  @frame_manager = frame_manager
  @client = client
  @parent_frame = parent_frame
  @id = frame_id
  @detached = false

  @loader_id = ''
  @lifecycle_events = Set.new
  @main_world = Puppeteer::DOMWorld.new(frame_manager, self, frame_manager.timeout_settings)
  @secondary_world = Puppeteer::DOMWorld.new(frame_manager, self, frame_manager.timeout_settings)
  @child_frames = Set.new
  if parent_frame
    parent_frame._child_frames << self
  end
end

Instance Attribute Details

#frame_managerObject

Returns the value of attribute frame_manager.



23
24
25
# File 'lib/puppeteer/frame.rb', line 23

def frame_manager
  @frame_manager
end

#idObject

Returns the value of attribute id.



23
24
25
# File 'lib/puppeteer/frame.rb', line 23

def id
  @id
end

#lifecycle_eventsObject

Returns the value of attribute lifecycle_events.



23
24
25
# File 'lib/puppeteer/frame.rb', line 23

def lifecycle_events
  @lifecycle_events
end

#loader_idObject

Returns the value of attribute loader_id.



23
24
25
# File 'lib/puppeteer/frame.rb', line 23

def loader_id
  @loader_id
end

#main_worldObject

Returns the value of attribute main_world.



23
24
25
# File 'lib/puppeteer/frame.rb', line 23

def main_world
  @main_world
end

#secondary_worldObject

Returns the value of attribute secondary_world.



23
24
25
# File 'lib/puppeteer/frame.rb', line 23

def secondary_world
  @secondary_world
end

Instance Method Details

#add_script_tag(script_tag) ⇒ !Promise<!ElementHandle>

Parameters:

Returns:



136
137
138
# File 'lib/puppeteer/frame.rb', line 136

def add_script_tag(script_tag)
  @main_world.add_script_tag(script_tag)
end

#add_style_tag(style_tag) ⇒ !Promise<!ElementHandle>

Parameters:

Returns:



142
143
144
# File 'lib/puppeteer/frame.rb', line 142

def add_style_tag(style_tag)
  @main_world.add_style_tag(style_tag)
end

#child_framesObject



126
127
128
# File 'lib/puppeteer/frame.rb', line 126

def child_frames
  @child_frames.dup
end

#click(selector, delay: nil, button: nil, click_count: nil) ⇒ Object

Parameters:

  • selector (String)
  • delay (Number) (defaults to: nil)
  • button (String) (defaults to: nil)

    “left”|“right”|“middle”

  • click_count (Number) (defaults to: nil)


150
151
152
# File 'lib/puppeteer/frame.rb', line 150

def click(selector, delay: nil, button: nil, click_count: nil)
  @secondary_world.click(selector, delay: delay, button: button, click_count: click_count)
end

#contentObject



97
98
99
# File 'lib/puppeteer/frame.rb', line 97

def content
  @secondary_world.content
end

#detachObject



277
278
279
280
281
282
283
284
285
# File 'lib/puppeteer/frame.rb', line 277

def detach
  @detached = true
  @main_world.detach
  @secondary_world.detach
  if @parent_frame
    @parent_frame._child_frames.delete(self)
  end
  @parent_frame = nil
end

#detached?Boolean

Returns:

  • (Boolean)


130
131
132
# File 'lib/puppeteer/frame.rb', line 130

def detached?
  @detached
end

#evaluate(page_function, *args) ⇒ Object

Parameters:

  • pageFunction (Function|string)
  • args (!Array<*>)


52
53
54
# File 'lib/puppeteer/frame.rb', line 52

def evaluate(page_function, *args)
  @main_world.evaluate(page_function, *args)
end

#evaluate_handle(page_function, *args) ⇒ !Promise<!Puppeteer.JSHandle>

Parameters:

  • pageFunction (Function|string)

Returns:



46
47
48
# File 'lib/puppeteer/frame.rb', line 46

def evaluate_handle(page_function, *args)
  @main_world.evaluate_handle(page_function, *args)
end

#execution_contextObject



40
41
42
# File 'lib/puppeteer/frame.rb', line 40

def execution_context
  @main_world.execution_context
end

#focus(selector) ⇒ Object

Parameters:

  • selector (string)


155
156
157
# File 'lib/puppeteer/frame.rb', line 155

def focus(selector)
  @secondary_world.focus(selector)
end

#goto(url, referer: nil, timeout: nil, wait_until: nil) ⇒ Puppeteer::Response

Parameters:

  • url (String)
  • rederer (String)
  • timeout (number|nil) (defaults to: nil)
  • wait_until (string|nil) (defaults to: nil)

    'load' | 'domcontentloaded' | 'networkidle0' | 'networkidle2'

Returns:

  • (Puppeteer::Response)


30
31
32
# File 'lib/puppeteer/frame.rb', line 30

def goto(url, referer: nil, timeout: nil, wait_until: nil)
  @frame_manager.navigate_frame(self, url, referer: referer, timeout: timeout, wait_until: wait_until)
end

#handle_lifecycle_event(loader_id, name) ⇒ Object



264
265
266
267
268
269
270
# File 'lib/puppeteer/frame.rb', line 264

def handle_lifecycle_event(loader_id, name)
  if name == 'init'
    @loader_id = loader_id
    @lifecycle_events.clear
  end
  @lifecycle_events << name
end

#handle_loading_stoppedObject



272
273
274
275
# File 'lib/puppeteer/frame.rb', line 272

def handle_loading_stopped
  @lifecycle_events << 'DOMContentLoaded'
  @lifecycle_events << 'load'
end

#hover(selector) ⇒ Object

Parameters:

  • selector (string)


160
161
162
# File 'lib/puppeteer/frame.rb', line 160

def hover(selector)
  @secondary_world.hover(selector)
end

#nameString

Returns:

  • (String)


108
109
110
# File 'lib/puppeteer/frame.rb', line 108

def name
  @name || ''
end

Parameters:

  • frame_payload (Hash)


248
249
250
251
252
253
254
255
256
257
# File 'lib/puppeteer/frame.rb', line 248

def navigated(frame_payload)
  @name = frame_payload['name']
  # TODO(lushnikov): remove this once requestInterception has loaderId exposed.
  @navigation_url = frame_payload['url']
  @url = frame_payload['url']

  # Ensure loaderId updated.
  # The order of [Page.lifecycleEvent name="init"] and [Page.frameNavigated] is random... for some reason...
  @loader_id = frame_payload['loaderId']
end

Parameters:

  • url (String)


260
261
262
# File 'lib/puppeteer/frame.rb', line 260

def navigated_within_document(url)
  @url = url
end

#parent_frameFrame?

Returns:



118
119
120
# File 'lib/puppeteer/frame.rb', line 118

def parent_frame
  @parent_frame
end

#S(selector) ⇒ !Promise<?Puppeteer.ElementHandle>

`$()` in JavaScript. $ is not allowed to use as a method name in Ruby.

Parameters:

  • selector (string)

Returns:



59
60
61
# File 'lib/puppeteer/frame.rb', line 59

def S(selector)
  @main_world.S(selector)
end

#select(selector, *values) ⇒ !Promise<!Array<string>>

Parameters:

  • selector (string)
  • values (!Array<string>)

Returns:

  • (!Promise<!Array<string>>)


167
168
169
# File 'lib/puppeteer/frame.rb', line 167

def select(selector, *values)
  @secondary_world.select(selector, *values)
end

#set_content(html, timeout: nil, wait_until: nil) ⇒ Object

Parameters:

  • html (string)
  • options (!{timeout?: number, waitUntil?: string|!Array<string>}=)


103
104
105
# File 'lib/puppeteer/frame.rb', line 103

def set_content(html, timeout: nil, wait_until: nil)
  @secondary_world.set_content(html, timeout: timeout, wait_until: wait_until)
end

#Seval(selector, page_function, *args) ⇒ !Promise<(!Object|undefined)>

`$eval()` in JavaScript. $ is not allowed to use as a method name in Ruby.

Parameters:

  • selector (string)
  • pageFunction (Function|string)
  • args (!Array<*>)

Returns:

  • (!Promise<(!Object|undefined)>)


77
78
79
# File 'lib/puppeteer/frame.rb', line 77

def Seval(selector, page_function, *args)
  @main_world.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.

Parameters:

  • selector (string)

Returns:



93
94
95
# File 'lib/puppeteer/frame.rb', line 93

def SS(selector)
  @main_world.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.

Parameters:

  • selector (string)
  • pageFunction (Function|string)
  • args (!Array<*>)

Returns:

  • (!Promise<(!Object|undefined)>)


86
87
88
# File 'lib/puppeteer/frame.rb', line 86

def SSeval(selector, page_function, *args)
  @main_world.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.

Parameters:

  • expression (string)

Returns:



67
68
69
# File 'lib/puppeteer/frame.rb', line 67

def Sx(expression)
  @main_world.Sx(expression)
end

#tap(selector) ⇒ Object

Parameters:

  • selector (string)


172
173
174
# File 'lib/puppeteer/frame.rb', line 172

def tap(selector)
  @secondary_world.tap(selector)
end

#titleObject



243
244
245
# File 'lib/puppeteer/frame.rb', line 243

def title
  @secondary_world.title
end

#type_text(selector, text, delay: nil) ⇒ Object

Parameters:

  • selector (String)
  • text (String)
  • delay (Number) (defaults to: nil)


179
180
181
# File 'lib/puppeteer/frame.rb', line 179

def type_text(selector, text, delay: nil)
  @main_world.type_text(selector, text, delay: delay)
end

#urlString

Returns:

  • (String)


113
114
115
# File 'lib/puppeteer/frame.rb', line 113

def url
  @url
end

#wait_for_function(page_function, options = {}, *args) ⇒ !Promise<!Puppeteer.JSHandle>

Parameters:

  • pageFunction (Function|string)
  • options (!{polling?: string|number, timeout?: number}=) (defaults to: {})
  • args (!Array<*>)

Returns:



239
240
241
# File 'lib/puppeteer/frame.rb', line 239

def wait_for_function(page_function, options = {}, *args)
  @main_world.wait_for_function(page_function, options, *args)
end

#wait_for_navigation(timeout: nil, wait_until: nil) ⇒ Object

Parameters:

  • timeout (number|nil) (defaults to: nil)
  • wait_until (string|nil) (defaults to: nil)

    'load' | 'domcontentloaded' | 'networkidle0' | 'networkidle2'



36
37
38
# File 'lib/puppeteer/frame.rb', line 36

def wait_for_navigation(timeout: nil, wait_until: nil)
  @frame_manager.wait_for_frame_navigation(self, timeout: timeout, wait_until: wait_until)
end

#wait_for_selector(selector, visible: nil, hidden: nil, timeout: nil) ⇒ Object

Parameters:

  • selector (String)
  • visible (Boolean) (defaults to: nil)

    Wait for element visible (not 'display: none' nor 'visibility: hidden') on true. default to false.

  • hidden (Boolean) (defaults to: nil)

    Wait for element invisible ('display: none' nor 'visibility: hidden') on true. default to false.

  • timeout (Integer) (defaults to: nil)


209
210
211
212
213
214
215
216
217
218
# File 'lib/puppeteer/frame.rb', line 209

def wait_for_selector(selector, visible: nil, hidden: nil, timeout: nil)
  handle = @secondary_world.wait_for_selector(selector, visible: visible, hidden: hidden, timeout: timeout)
  if !handle
    return nil
  end
  main_execution_context = @main_world.execution_context
  result = main_execution_context.adopt_element_handle(handle)
  handle.dispose
  result
end

#wait_for_xpath(xpath, visible: nil, hidden: nil, timeout: nil) ⇒ Object

Parameters:

  • xpath (String)
  • visible (Boolean) (defaults to: nil)

    Wait for element visible (not 'display: none' nor 'visibility: hidden') on true. default to false.

  • hidden (Boolean) (defaults to: nil)

    Wait for element invisible ('display: none' nor 'visibility: hidden') on true. default to false.

  • timeout (Integer) (defaults to: nil)


224
225
226
227
228
229
230
231
232
233
# File 'lib/puppeteer/frame.rb', line 224

def wait_for_xpath(xpath, visible: nil, hidden: nil, timeout: nil)
  handle = @secondary_world.wait_for_xpath(xpath, visible: visible, hidden: hidden, timeout: timeout)
  if !handle
    return nil
  end
  main_execution_context = @main_world.execution_context
  result = main_execution_context.adopt_element_handle(handle)
  handle.dispose
  result
end