Class: Ferrum::Console::Location

Inherits:
Object
  • Object
show all
Defined in:
lib/ferrum/console/location.rb,
sig/ferrum/console/location.rbs

Overview

A place in the page's source a Message points at: where console.* was called, an exception was thrown or a resource failed to load. Line and column numbers are 1-based.

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(url:, line: nil, column: nil, function_name: "") ⇒ Location

Returns a new instance of Location.

Parameters:

  • url: (String)
  • line: (::Integer, nil) (defaults to: nil)
  • column: (::Integer, nil) (defaults to: nil)
  • function_name: (String) (defaults to: "")


27
28
29
30
31
32
# File 'lib/ferrum/console/location.rb', line 27

def initialize(url:, line: nil, column: nil, function_name: "")
  @url = url
  @line = line
  @column = column
  @function_name = function_name
end

Instance Attribute Details

#column ⇒ ::Integer? (readonly)

Returns the value of attribute column.

Returns:

  • (::Integer, nil)


11
12
13
# File 'lib/ferrum/console/location.rb', line 11

def column
  @column
end

#function_name ⇒ String (readonly)

Returns the value of attribute function_name.

Returns:

  • (String)


11
12
13
# File 'lib/ferrum/console/location.rb', line 11

def function_name
  @function_name
end

#line ⇒ ::Integer? (readonly)

Returns the value of attribute line.

Returns:

  • (::Integer, nil)


11
12
13
# File 'lib/ferrum/console/location.rb', line 11

def line
  @line
end

#url ⇒ String (readonly)

Returns the value of attribute url.

Returns:

  • (String)


11
12
13
# File 'lib/ferrum/console/location.rb', line 11

def url
  @url
end

Class Method Details

.from_frame(frame) ⇒ Location

Builds a location from a CDP Runtime.CallFrame, or from the url and lineNumber of a Log.LogEntry. CDP numbers lines and columns from 0.

Parameters:

  • frame (Hash{String => Object})

Returns:



20
21
22
23
24
25
# File 'lib/ferrum/console/location.rb', line 20

def self.from_frame(frame)
  new(url: frame["url"].to_s,
      line: frame["lineNumber"]&.+(1),
      column: frame["columnNumber"]&.+(1),
      function_name: frame["functionName"].to_s)
end

Instance Method Details

#to_s ⇒ String

The location as url:line:column, leaving out what's unknown.

Returns:

  • (String)


37
38
39
# File 'lib/ferrum/console/location.rb', line 37

def to_s
  [url, line, column].compact.join(":")
end