class WebkitRemote::Client::ConsoleMessage

Data about an entry in the debugger console.

Attributes

level[R]

@return [Symbol] message severity

The documented values are :debug, :error, :log, :tip, and :warning.

network_resource[R]

@return [WebkitRemote::Client::NetworkResource] resource associated with

this message

This is set for console messages that indicate network errors.

params[R]

@return [Array<WebkitRemote::Client::JsObject>] extra arguments given

to the message
reason[R]

@return [Symbol] the component that produced this message

The documented values are :console_api, :html, :javascript, :network,

:other, :wml, and :xml.
source_line[R]

@return [Integer] the line number of the statement that caused this message

source_url[R]

@return [String] the URL of the file that caused this message

stack_trace[R]

@return [Array<Hash<Symbol, Object>>] JavaScript stack trace to the

statement that caused this message
text[R]

@return [String] the message text

Public Class Methods

new(raw_message, client) click to toggle source

@private Use Event#for instead of calling this constructor directly.

@param [Hash<String, Object>] the raw JSON for a Message object in the

Console domain, returned by a RPC call to a Webkit debugging server

@

# File lib/webkit_remote/client/console.rb, line 93
def initialize(raw_message, client)
  @level = (raw_message['level'] || 'error').to_sym
  @source_line = raw_message['line'] ? raw_message['line'].to_i : nil
  if raw_message['networkRequestId']
    @network_resource =
      client.network_resource raw_message['networkRequestId']
  else
    @network_resource = nil
  end
  if raw_message['parameters']
    @params = raw_message['parameters'].map do |raw_object|
      WebkitRemote::Client::JsObject.for raw_object, client, nil
    end
  else
    @params = []
  end
  @params.freeze
  if raw_message['source']
    @reason = raw_message['source'].gsub('-', '_').to_sym
  else
    @reason = :other
  end
  @stack_trace = self.class.parse_stack_trace raw_message['stackTrace']
  @text = raw_message['text']
  @source_url = raw_message['url']
end
parse_stack_trace(raw_stack_trace) click to toggle source

Parses a StackTrace object returned by a RPC request.

@param [Array<String, Object>] raw_stack_trace the raw StackTrace object

in the Console domain returned by a RPC request

@return [Array<Symbol, Object>] Ruby-friendly stack trace

# File lib/webkit_remote/client/console.rb, line 134
def self.parse_stack_trace(raw_stack_trace)
  return nil unless raw_stack_trace

  raw_stack_trace.map do |raw_frame|
    frame = {}
    if raw_frame['columnNumber']
      frame[:column] = raw_frame['columnNumber'].to_i
    end
    if raw_frame['lineNumber']
      frame[:line] = raw_frame['lineNumber'].to_i
    end
    if raw_frame['functionName']
      frame[:function] = raw_frame['functionName']
    end
    if raw_frame['url']
      frame[:url] = raw_frame['url']
    end
    frame
  end
end

Public Instance Methods

release_params() click to toggle source

Releases the JavaScript objects referenced by this message's parameters.

# File lib/webkit_remote/client/console.rb, line 121
def release_params
  @params.each do |param|
    if param.kind_of?(WebkitRemote::Client::JsObject)
      param.release
    end
  end
end