Skip to content

Instantly share code, notes, and snippets.

@fernyb
Created April 30, 2018 23:04
Show Gist options
  • Save fernyb/039f1198cdef1af109f2a9eed2e9dbac to your computer and use it in GitHub Desktop.
Save fernyb/039f1198cdef1af109f2a9eed2e9dbac to your computer and use it in GitHub Desktop.
Headless Chrome Network Traffic
@entries ||= []
selenium_driver = page.driver.browser
performance_log = selenium_driver.manage.logs.get("performance")
performance_log.each do |log|
json = JSON.parse(log.message)
if msg = json['message']
if msg['method'] == "Network.requestWillBeSent"
_params = msg['params']
url = _params['request']['url']
if url.present? && url =~ /^http/
begin
uri = URI.parse(url)
rescue URI::InvalidURIError => e
next
end
params = Rack::Utils.parse_nested_query(uri.query)
@entries << {
:scheme => uri.scheme,
:host => uri.host,
:request_uri => uri.request_uri,
:query => params,
:url => url
}
end
end
end
end
@entries
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment