Skip to content

Instantly share code, notes, and snippets.

@jarib
Created July 13, 2010 22:11
Show Gist options
  • Save jarib/474618 to your computer and use it in GitHub Desktop.
Save jarib/474618 to your computer and use it in GitHub Desktop.
yslow beacon
require 'rubygems'
require 'selenium-webdriver'
require 'rack'
require 'thin'
require 'socket'
require 'pp'
Thread.abort_on_exception = true
class Server
attr_reader :data
def initialize
@data = []
end
def call(env)
@data << JSON.parse(env['rack.input'].read)
[200, {}, []]
end
def run!
@thread = Thread.new { Rack::Handler::Thin.run(self, :Port => port) }
sleep 0.5 until listening?
end
def port
3580
end
def url
"http://localhost:#{port}/"
end
def listening?
TCPSocket.new("localhost", port).close
true
rescue
false
end
def join
@thread.join if @thread
end
end
server = Server.new
server.run!
profile = Selenium::WebDriver::Firefox::Profile.new
# need selenium-webdriver >= 0.0.25 for this
profile.add_extension "firebug-1.5.4-fx.xpi"
profile.add_extension "yslow-2.0.7-fx.xpi"
# http://developer.yahoo.com/yslow/help/beacons.html#yslow_beacon
profile["extensions.yslow.autorun"] = true
profile["extensions.yslow.optinBeacon"] = true
profile["extensions.yslow.beaconUrl"] = server.url
profile["extensions.yslow.beaconInfo"] = 'all'
profile["extensions.firebug.allPagesActivation"] = 'on'
browser = Selenium::WebDriver.for :firefox, :profile => profile
browser.get "http://google.com"
browser.close
pp server.data
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment