oesmith / puffing-billy

A rewriting web proxy for testing interactions between your browser and external sites. Works with ruby + rspec.
MIT License
656 stars 170 forks source link

Proxy errors in Docker + Headless Chrome + Selenium #296

Closed codemang closed 4 years ago

codemang commented 4 years ago

As I mentioned, I'm running a SPA (React) in a Docker container using Headless Chrome.

Here is my testing config:

require 'capybara/rails'
require 'capybara/rspec'

Capybara.server = :puma, { Silent: true }

Capybara.register_driver :headless_chrome do |app|
  capabilities = {
    chromeOptions: {
      w3c:  false,
      args: [
        '--headless',
        '--disable-gpu',
        '--no-sandbox', # Sandbox cannot be used inside unprivileged Docker container
        '--window-size=1280,720', # Increasing resolution seems to affect spec flakiness...
        # Reduces headless Chrome memory and decreases spec runtime by about 20%.
        ENV['SHOULD_CHROMEDRIVER_DISABLE_IMAGES'] == 'true' ? '--blink-settings=imagesEnabled=false' : nil,

       # All the new settings I've added to try to fix this problem
        "--proxy-server=#{Billy.proxy.host}:#{Billy.proxy.port}",
        "proxy-server=#{Billy.proxy.host}:#{Billy.proxy.port}",
        '--proxy-bypass-list=127.0.0.1',
        '--tls13-variant=disabled',
        '--ignore-certificate-errors',
        '--allow-insecure-localhost',
        'acceptInsecureCerts',
        '--accept-insecure-certs',
      ].compact,
    },
    loggingPrefs:  {
      browser: 'ALL',
    },
  }

  Capybara::Selenium::Driver.new(
    app,
    browser:              :chrome,
    desired_capabilities: Selenium::WebDriver::Remote::Capabilities.chrome(capabilities),
  )
end

Capybara.javascript_driver = :headless_chrome

When I run the specs I get this error:

📜   severe
     http://fonts.googleapis.com/css?family=Nunito+Sans:400,600,700|Domine:400&display=swap - Failed to load resource: net::ERR_EMPTY_RESPONSE

I'm getting SSL errors, but I specifically changed this one to use HTTP to rule out SSL as an issue.

What could be causing this?

ronwsmith commented 4 years ago

What do you see in your log files in the app?

Also, you can look to mirror the options in the default driver config.

codemang commented 4 years ago

Ah I was missing a config argument for the browser, thanks!