Last active
December 9, 2022 03:45
-
-
Save samnissen/85e83d5216ade867f3c5 to your computer and use it in GitHub Desktop.
Get a HAR export of internet activity triggered by a passing a URL to a browser with Ruby and Watir-Webdriver
This file contains 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
require 'watir-webdriver' | |
profile = Selenium::WebDriver::Firefox::Profile.new | |
profile.add_extension "/your/path/to/Firefox/profile/extensions/firebug@software.joehewitt.com.xpi" | |
profile.add_extension "/your/path/to/Firefox/profile/extensions/netexport@getfirebug.com.xpi" | |
profile["extensions.firebug.currentVersion"] = "2.0.14" # Supress "What's new in Firebug" tab from opening. | |
profile["extensions.firebug.delayLoad"] = false | |
profile["extensions.firebug.showFirstRunPage"] = false | |
profile["extensions.firebug.console.enableSites"] = true | |
profile["extensions.firebug.net.enableSites"] = true | |
profile["extensions.firebug.script.enableSites"] = true | |
profile["extensions.firebug.defaultPanelName"] = 'net' | |
profile["extensions.firebug.allPagesActivation"] = "on" | |
profile["extensions.firebug.netexport.alwaysEnableAutoExport"] = true | |
profile["extensions.firebug.netexport.showPreview"] = false | |
profile["extensions.firebug.netexport.defaultLogDir"] = "/your/preferred/path/for/hars" | |
profile["extensions.firebug.netexport.autoExportToServer"] = false | |
profile["extensions.firebug.netexport.sendToConfirmation"] = false | |
profile["extensions.firebug.netexport.pageLoadedTimeout"] = 2500 | |
profile["extensions.firebug.netexport.Automation"] = true | |
profile["extensions.firebug.netexport.saveFiles"] = true | |
b = Watir::Browser.new :firefox, :profile => profile | |
b.goto "http://your-site.com" | |
# Do whatever else you need to do. | |
b.close if b | |
require 'har' | |
h = HAR::Archive.from_file("/your/preferred/path/for/hars/yourfile.har") | |
# Access your archive, a JSON hash of each network call, and its timing | |
# Example: Search for calls to 'facebook' | |
h.entries.map{|e| e.request.url if e.request.url.include?("facebook")}.compact | |
# => ["http://connect.facebook.net/en_US/acbd.js", "https://www.facebook.com/tr/?id=123456&ev=PixelInitialized&dl=http%3A%2F%2Fwww.yoursite.com%2F&rl=&if=false&ts=123456", "http://www.facebook.com/fr/u.php?p=123456&m=332211", "https://www.facebook.com/fr/u.php?p=123456&m=112233", "http://match.adsrvr.org/track/cmf/generic?ttd_pid=facebook"] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment