Created
April 23, 2020 01:32
-
-
Save PandaWhisperer/e77f1fa381c0ff49150a504ec1a52800 to your computer and use it in GitHub Desktop.
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 'capybara' | |
require 'capybara/apparition' | |
require 'forwardable' | |
Capybara.threadsafe = true | |
Capybara.register_driver :apparition do |app| | |
Capybara::Apparition::Driver.new(app, headless: true, | |
js_errors: false, | |
browser_logger: nil) | |
end | |
class HeadlessChrome | |
attr_reader :session | |
extend Forwardable | |
delegate Capybara::Session::DSL_METHODS => :session | |
def initialize | |
@session = Capybara::Session.new(:apparition) | |
end | |
def crawl(url, &block) | |
session.visit(url) | |
self.instance_eval &block | |
end | |
def network_requests | |
session.driver.network_traffic | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment