Class: WebkitRemote::Event::NetworkRequest

Inherits:
WebkitRemote::Event show all
Defined in:
lib/webkit_remote/client/network_events.rb

Overview

Emitted right before a network request.

Instance Attribute Summary collapse

Attributes inherited from WebkitRemote::Event

#domain, #name, #raw_data

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from WebkitRemote::Event

can_receive?, class_for, for, #matches?, register, register_class

Constructor Details

#initialize(rpc_event, client) ⇒ NetworkRequest

Returns a new instance of NetworkRequest.



137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
# File 'lib/webkit_remote/client/network_events.rb', line 137

def initialize(rpc_event, client)
  super
  @document_url = raw_data['documentURL']
  if raw_data['initiator']
    @initiator = WebkitRemote::Client::NetworkRequestInitiator.new(
        raw_data['initiator'])
  end
  @loader_id = raw_data['loaderId']
  if raw_data['request']
    @request = WebkitRemote::Client::NetworkRequest.new(
        raw_data['request'])
  end
  if raw_data['redirectResponse']
    @redirect_response = WebkitRemote::Client::NetworkResponse.new(
        raw_data['redirectResponse'])
  end
  if raw_data['stackTrace']
    @stack_trace = WebkitRemote::Client::ConsoleMessage.parse_stack_trace(
        raw_initiator['stackTrace'])
  else
    @stack_trace = nil
  end
  @timestamp = raw_data['timestamp']

  @resource = client.network_resource raw_data['requestId']
  @resource.set_document_url @document_url
  @resource.set_initiator @initiator
  @resource.set_request @request
  # TODO(pwnall): consider tracking redirects
  @resource.add_event self
end

Instance Attribute Details

#document_urlString (readonly)

Returns the URL of the document that caused this network request.

Returns:

  • (String)

    the URL of the document that caused this network request



120
121
122
# File 'lib/webkit_remote/client/network_events.rb', line 120

def document_url
  @document_url
end

#initiatorWebkitRemote::Client::NetworkRequestInitiator (readonly)

Returns cause for this network request.

Returns:



124
125
126
# File 'lib/webkit_remote/client/network_events.rb', line 124

def initiator
  @initiator
end

#loader_idString (readonly)

Returns used to correlate events.

Returns:

  • (String)

    used to correlate events



131
132
133
# File 'lib/webkit_remote/client/network_events.rb', line 131

def loader_id
  @loader_id
end

#redirect_responseWebkitRemote::Client::NetworkResponse (readonly)

Returns the HTTP redirect that caused this request; can be nil.

Returns:



128
129
130
# File 'lib/webkit_remote/client/network_events.rb', line 128

def redirect_response
  @redirect_response
end

#requestWebkitRemote::Client::NetworkRequest (readonly)

Returns information about this network request.

Returns:



117
118
119
# File 'lib/webkit_remote/client/network_events.rb', line 117

def request
  @request
end

#resourceWebkitRemote::Client::NetworkResource (readonly)

Returns information about the resource fetched by this network operation.

Returns:



113
114
115
# File 'lib/webkit_remote/client/network_events.rb', line 113

def resource
  @resource
end

#timestampNumber (readonly)

Returns the event timestamp.

Returns:

  • (Number)

    the event timestamp



134
135
136
# File 'lib/webkit_remote/client/network_events.rb', line 134

def timestamp
  @timestamp
end

Class Method Details

.can_reach?(client) ⇒ Boolean

Returns:

  • (Boolean)


170
171
172
# File 'lib/webkit_remote/client/network_events.rb', line 170

def self.can_reach?(client)
  client.network_events
end