MachinePublishers / jBrowserDriver

A programmable, embeddable web browser driver compatible with the Selenium WebDriver spec -- headless, WebKit-based, pure Java
Other
809 stars 143 forks source link

SOCKS or HTTP proxy settings are not respected #330

Closed zzvara closed 5 years ago

zzvara commented 5 years ago

Hi!

I'm setting up and invoking the JBrowserDriver using the following Scala code:

new JBrowserDriver {
          var settings = Settings
            .builder()
            .timezone(Timezone.EUROPE_BUDAPEST)
            .blockAds(true)
            .cache(cacheEnabled)
            .cacheEntries(cacheSize)
            .connectionReqTimeout(requestTimeout)
            .connectTimeout(connectionTimeout)
            .ajaxResourceTimeout(requestTimeout)
            .socketTimeout(connectionTimeout)
            .headless(true)
            .hostnameVerification(false)
            .ignoreDialogs(true)
            .saveMedia(false)
            /**
              * @see [issue #220 on Github]
              */
            .javaOptions(jvmOptions: _*)
            .ssl("trustanything")
            .userAgent(agent)
          if (proxyEnabled) {
            logInfo(s"Using proxy [$proxyHost:$proxyPort] with type [$proxyType].")
            settings = settings.proxy(new ProxyConfig(proxyType, proxyHost, proxyPort))
          }
          settings.build()
        }
      }

A proxy should be available on localhost:8080 (socket). I have debugged the driver so far to verify that proxy settings reach correct variables, but I have found no evidence that the proxy settings are accessed on a code path that is actually executed. I execute a fetch with the following code:

b = pool.borrowObject(borrowMaximumWait)
b.get(address)
b.getPageSource

The getPageSource will return correctly even if the proxy is not running on port 8080.

Tried HTTP proxy as well, does not work - although worked through FireFox browser.

I'm looking for guidance to further debug the code, moreover, I have the following questions:

  1. If a proxy connection fails, would the fetch b.get(address) also fail? In other words, will it fallback to a non-socket, default connection if the socket's port refuses connection?
  2. Is this feature (socket proxy) stable? I have found issue https://github.com/MachinePublishers/jBrowserDriver/issues/239, which still look like to be open. Is that related?
  3. Could you help me on how to debug?

Cheers, Zoltán