module WebkitRemote::Client::Network

API for the Network domain.

Attributes

disable_cache[R]

@return [Boolean] true if the browser's network cache is disabled, so every

resource load generates an HTTP request
http_headers[R]

@return [Hash<String, String>]

network_events[R]

@return [Boolean] true if the debugger generates Network.* events

network_resources[R]

@return [Array<WebkitRemote::Client::NetworkResource>] the resources

fetched during the debugging session

This is only populated when Network events are received.

user_agent[R]

@return [String] replaces the brower's built-in User-Agent string

Public Instance Methods

can_clear_cookies?() click to toggle source

Checks if the debugger can clear the browser's cookies.

@return [Boolean] true if WebkitRemote::Client::Network#clear_cookies can

be succesfully called
# File lib/webkit_remote/client/network.rb, line 64
def can_clear_cookies?
  response = @rpc.call 'Network.canClearBrowserCookies'
  !!response['result']
end
can_clear_network_cache?() click to toggle source

Checks if the debugger can clear the browser's cache.

@return [Boolean] true if WebkitRemote::Client::Network#clear_network_cache

can be succesfully called
# File lib/webkit_remote/client/network.rb, line 81
def can_clear_network_cache?
  response = @rpc.call 'Network.canClearBrowserCache'
  !!response['result']
end
clear_cookies() click to toggle source

Removes all the cookies in the debugged browser.

@return [WebkitRemote::Client] self

# File lib/webkit_remote/client/network.rb, line 72
def clear_cookies
  @rpc.call 'Network.clearBrowserCookies'
  self
end
clear_network() click to toggle source

Removes the cached network request information.

@return [WebkitRemote::Client] self

# File lib/webkit_remote/client/network.rb, line 134
def clear_network
  @network_resource_hash.clear
  @network_resources.clear
  self
end
clear_network_cache() click to toggle source

Removes all the cached data in the debugged browser.

@return [WebkitRemote::Client] self

# File lib/webkit_remote/client/network.rb, line 89
def clear_network_cache
  @rpc.call 'Network.clearBrowserCache'
  self
end
disable_cache=(new_disable_cache) click to toggle source

Enables or disables the use of the network cache.

@param [Boolean] new_disable_cache if true, the browser will not use its

network cache, and will always generate HTTP requests
# File lib/webkit_remote/client/network.rb, line 24
def disable_cache=(new_disable_cache)
  new_disable_cache = !!new_disable_cache
  if new_disable_cache != disable_cache
    @rpc.call 'Network.setCacheDisabled', cacheDisabled: new_disable_cache
    @disable_cache = new_disable_cache
  end
  new_disable_cache
end
http_headers=(new_http_headers) click to toggle source

Sets extra headers to be sent with every HTTP request.

@param [Hash<String, String>] new_extra_headers HTTP headers to be added to

every HTTP request sent by the browser
# File lib/webkit_remote/client/network.rb, line 49
def http_headers=(new_http_headers)
  new_http_headers = Hash[new_http_headers.map { |k, v|
    [k.to_s, v.to_s]
  }].freeze
  if new_http_headers != http_headers
    @rpc.call 'Network.setExtraHTTPHeaders', headers: new_http_headers
    @http_headers = new_http_headers
  end
  new_http_headers
end
initialize_network() click to toggle source

@private Called by the Client constructor to set up Network data.

# File lib/webkit_remote/client/network.rb, line 141
def initialize_network
  @disable_cache = false
  @network_events = false
  @network_resources = []
  @network_resource_hash = {}
  @user_agent = nil
end
network_events=(new_network_events) click to toggle source

Enables or disables the generation of events in the Network domain.

@param [Boolean] new_network_events if true, the browser debugger will

generate Network.* events
# File lib/webkit_remote/client/network.rb, line 11
def network_events=(new_network_events)
  new_network_events = !!new_network_events
  if new_network_events != network_events
    @rpc.call(new_network_events ? 'Network.enable' : 'Network.disable')
    @network_events = new_network_events
  end
  new_network_events
end
network_resource(remote_id) click to toggle source

Looks up network resources by IDs assigned by the WebKit remote debugger.

@private Use the resource property of Network events instead of calling

this directly.

@param [String] remote_id the WebKit-assigned request_id @return [WebkitRemote::Client::NetworkResource] the cached information

about the resource with the given ID
# File lib/webkit_remote/client/network.rb, line 121
def network_resource(remote_id)
  if @network_resource_hash[remote_id]
    return @network_resource_hash[remote_id]
  end
  resource = WebkitRemote::Client::NetworkResource.new remote_id, self

  @network_resources << resource
  @network_resource_hash[remote_id] = resource
end
user_agent=(new_user_agent) click to toggle source

Sets the User-Agent header that the browser will use to identify itself.

@param [String] new_user_agent will be used instead of the browser's

hard-coded User-Agent header
# File lib/webkit_remote/client/network.rb, line 37
def user_agent=(new_user_agent)
  if new_user_agent != user_agent
    @rpc.call 'Network.setUserAgentOverride', userAgent: new_user_agent
    @user_agent = new_user_agent
  end
  new_user_agent
end