Module: Ferrum::Page::Frames

Included in:
Ferrum::Page
Defined in:
lib/ferrum/page/frames.rb

Overview

Tracks the page's frame tree and keeps it in sync with the browser by subscribing to the relevant Page.*, Network.*, and Runtime.* CDP events. Exposes lookups over the tracked Frame objects and reports when the tree has settled into an idle state.

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#main_frameFrame (readonly)

The page's main frame, the top of the tree and the parent of all frames.

Returns:



17
18
19
# File 'lib/ferrum/page/frames.rb', line 17

def main_frame
  @main_frame
end

Instance Method Details

#frame_by(id: nil, name: nil, execution_id: nil) ⇒ Frame?

Find a frame by given params.

Examples:

page.frame_by(id: "C6D104CE454A025FBCF22B98DE612B12")

Parameters:

  • id (String) (defaults to: nil)

    Unique frame's id that page provides.

  • name (String) (defaults to: nil)

    Frame's name if there's one.

  • execution_id (String) (defaults to: nil)

    Frame's context execution id.

Returns:

  • (Frame, nil)

    The matching frame.



62
63
64
65
66
67
68
69
70
# File 'lib/ferrum/page/frames.rb', line 62

def frame_by(id: nil, name: nil, execution_id: nil)
  if id
    @frames[id]
  elsif name
    frames.find { |f| f.name == name }
  elsif execution_id
    frames.find { |f| f.execution_id == execution_id }
  end
end

#framesArray<Frame>

Returns all the frames current page have.

Examples:

page.go_to("https://www.w3schools.com/tags/tag_frame.asp")
page.frames # =>
# [
#   #<Ferrum::Frame
#     @id="C6D104CE454A025FBCF22B98DE612B12"
#     @parent_id=nil @name=nil @state=:stopped_loading @execution_id=1>,
#   #<Ferrum::Frame
#     @id="C09C4E4404314AAEAE85928EAC109A93"
#     @parent_id="C6D104CE454A025FBCF22B98DE612B12" @state=:stopped_loading @execution_id=2>,
#   #<Ferrum::Frame
#     @id="2E9C7F476ED09D87A42F2FEE3C6FBC3C"
#     @parent_id="C6D104CE454A025FBCF22B98DE612B12" @state=:stopped_loading @execution_id=3>,
#   ...
# ]

Returns:



40
41
42
# File 'lib/ferrum/page/frames.rb', line 40

def frames
  @frames.values
end