Created
April 30, 2018 23:04
-
-
Save fernyb/039f1198cdef1af109f2a9eed2e9dbac to your computer and use it in GitHub Desktop.
Headless Chrome Network Traffic
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@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