Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Firefox 48+ (Geckodriver) not using Proxy Data #334

Closed
aberndt opened this issue Oct 5, 2016 · 14 comments
Closed

Firefox 48+ (Geckodriver) not using Proxy Data #334

aberndt opened this issue Oct 5, 2016 · 14 comments
Labels
bug Something isn't working

Comments

@aberndt
Copy link

aberndt commented Oct 5, 2016

Hello,
i use selenium 3 beta3 in combination with the newest Firefox (49) and the newest php-webdriver. But i can't handle it to let firefox use proxy settings. my code is as following:

host = 'http://localhost:4444/wd/hub'; // this is the default
$capabilities = DesiredCapabilities::firefox();
$capabilities->setCapability(
    WebDriverCapabilityType::PROXY,
            array(
                'proxyType' => 'manual',
                'ftpProxy' => '111.111.111.111:80',
                'httpProxy' => '111.111.111.111:80',
                'sslProxy' => '111.111.111.111:80',
                'socksProxy' => '111.111.111.111:80',
                //'noProxy' => '127.0.0.1'
            )
        );
$webdriver = RemoteWebDriver::create($host, $capabilities, 5000);
$webdriver->get('http://wieistmeineip.de');

111.111.111.111 is just a dummy IP, i am not allowed to write the real IP here.
It opens the Firefox and navigates to the webpage but it does not use the Proxy settings. What am i doing wrong ?

Thanks
Andreas

@OndraM
Copy link
Collaborator

OndraM commented Oct 14, 2016

Hi, proxy settings works for me (however, I didn't try with Selenium 3 and Firefox 49). Are you able try it in Firefox 47.0.1 (or Firefox ESR), please?

@mb-joker
Copy link

@aberndt exact same problem here but with ff 50.0 and selenium-server-standalone-3.0.0.jar

@OndraM OndraM added the bug Something isn't working label Dec 17, 2016
@OndraM
Copy link
Collaborator

OndraM commented Dec 17, 2016

So I've dived into the issue, and find multiple problems there. Basically if you rely on proxy, you right now have these options:

  1. Use your current code and Capability settings, but only with Selenium 2.53.1 + Firefox ESR (or Firefox 47.0.1),
  2. Or use other Selenium driver, like Chromedriver
  3. Or use Firefox 48+ and Selenium 3, but then you have to change the way proxy settings is passed to Selenium. The reason is Proxy support mozilla/geckodriver#97 & Java+Selenium+Firefox proxy server cannot be set. SeleniumHQ/selenium#2963 - GeckoDriver (= Firefox 48+) reads the proxy settings only from requiredCapabilities, not from desiredCapabilities. As php-webdriver currently does not provide a way how to pass requiredCapabilities to Selenium (I will address this issue separately later), you need to pass it manually, as port of the desiredCapabilities when creating WebDriver instance:
<?php

$capabilities = DesiredCapabilities::firefox();
$capabilities->setCapability(
    [
        WebDriverCapabilityType::PROXY => [
            'proxyType' => 'MANUAL',
            'httpProxy' => 'proxy.foo.bar,
            'httpProxyPort' => 8118,
            'sslProxy' => 'proxy.foo.bar',
            'sslProxyPort' => 8118,
        ]
);

$driver = RemoteWebDriver::create('http://localhost:4444/wd/hub', $capabilities);

Also note the Geckodriver (Firefox 48+) requires passing the port as standalone property (it was part of the URL previously).

I may in future add some compatibility layer; but with current php-webdriver the options are as stated above.

@OndraM OndraM changed the title Firefox not using Proxy Data Firefox 48+ (Geckodriver) not using Proxy Data Dec 17, 2016
@OndraM
Copy link
Collaborator

OndraM commented Jan 9, 2017

Also see https://bugzilla.mozilla.org/show_bug.cgi?id=1326534 - the issue that proxy capabilities are not being read by GeckoDriver should now be fixed in Firefox, and should ship with Firefox 53.

@OndraM
Copy link
Collaborator

OndraM commented Mar 8, 2017

The Proxy should be working in Firefox 52 (with latest Selenium server and Geckodriver). Could somebody please confirm this?

Also note the proxy port must now be passed separately (unlike in previous Firefox versions) using httpProxyPort and sslProxyPort properties.

Ref. mozilla/geckodriver#97

@stone8
Copy link

stone8 commented Mar 29, 2017

Proxy configuration not picked up by GeckoDriver. I tried all the options from mozilla/geckodriver#97 (see my comments there) and SeleniumHQ/selenium#2963, and still can't get it working.

Selenium: 3.3.1
geckodriver 0.15 ( I tried each of v0.11, through v0.15)
mac os.version: '10.12.4',
java.version: '1.8.0_121'
Driver info: org.openqa.selenium.firefox.FirefoxDriver

@OndraM
Copy link
Collaborator

OndraM commented Mar 29, 2017

@stone8 Could you please provide the exact code you use to setup the proxy?

@xshaka
Copy link

xshaka commented Apr 4, 2017

@OndraM, I'm currently using Selenium: 3.3.1, geckodriver 0.15, and this is the code I use to set up the proxy, but it doesn't work.

        DesiredCapabilities required = new DesiredCapabilities();
        JsonObject proxyData = new JsonObject();
        proxyData.addProperty("proxyType", "MANUAL");
        final String HOST = "proxyHost";
        final int PORT = proxyPort;
        proxyData.addProperty("httpProxy", HOST);
        proxyData.addProperty("httpProxyPort", PORT);
        proxyData.addProperty("sslProxy", HOST);
        proxyData.addProperty("sslProxyPort", PORT);
        required.setCapability(CapabilityType.PROXY, proxyData);
        WebDriver driver = new FirefoxDriver(targetCapabilities, required);

@stone8
Copy link

stone8 commented Apr 7, 2017

Selenium 3.3.1, geckodirver 0.51, firefox 52.0:

Caused by: org.openqa.selenium.SessionNotCreatedException: InvalidArgumentError: Expected [object String] "{"proxyAutoconfigUrl":null,"autodetect":false,"socksUsername":null,"socksPassword":null,"httpProxy":"xxxxxxxx.com:8888","proxyType":"MANUAL","noProxy":null,"ftpProxy":"XXXXXXcom:8888","socksProxy":"xxxxxxx.com:8888","hCode":2082351774,"class":"org.openqa.selenium.Proxy","sslProxy":"xxxxxxxx.com:8888"}" to be an object (WARNING: The server did not provide any stacktrace information)
Command duration or timeout: 0 milliseconds
--------------------code-----------------

            ```
            Proxy tmpProxy = new Proxy();
            tmpProxy.setProxyType(Proxy.ProxyType.MANUAL);
            tmpProxy.setHttpProxy(PROXY_HOST_NAME_PORT_PAIR);
            tmpProxy.setFtpProxy(PROXY_HOST_NAME_PORT_PAIR);
            tmpProxy.setSslProxy(PROXY_HOST_NAME_PORT_PAIR);
            tmpProxy.setSocksProxy(PROXY_HOST_NAME_PORT_PAIR);
            capabilities.setCapability(CapabilityType.PROXY, tmpProxy);

            ...
            capabilities.setCapability(FirefoxDriver.PROFILE, profile);

            ...
            case FIREFOX_LOCAL:
        FirefoxProfile profile = (FirefoxProfile) capabilities.getCapability(FirefoxDriver.PROFILE);
        System.setProperty("webdriver.gecko.driver", "/Users/xxxxxxx/Downloads/geckodriver"); 
        return new FirefoxDriver(new FirefoxBinary(), profile, capabilities);

@stone8
Copy link

stone8 commented Apr 7, 2017

Selenium 3.3.1, geckodirver 0.51, firefox 45.8.0:
Caused by: org.openqa.selenium.SessionNotCreatedException: Not all requiredCapabilities could be met: ["[object Object] does not equal undefined","UEsDBBQACAgIALxxxxxxxxxxxxxxxxxxHAAAAdXNlci5qc51WTW/jNhC991cUPrVATSSb7qU9pdkUKLBoijWCPRIUORIZUyTLDyvur+9QH2vHlql4T7akGXLmzZs3kwJ46jzUP60qbzt8IoHV0P9XpiEt0x3zQMCwSoNY/fJjzXSAn3//IR08BYto46yP2UUC01EOzwSNdoov+BuInfVbImN0xEkV5H6dPzsWwlqDaaJExw8fP751mwL2wAT+CIjAI4g/lQ/xHmPhGtAt+nQarm0xr1fKpbct0MC9cpH6ZGhUbXa5u5m/KLIqEITDPJkHbQPMZzNZC9sZbZnAuwxrMrDSdl8lmA2ilZGad3cYlIshX0ZbK5hewB520VodCHhvPbcmWH0M93n6QTXGGkSthbYCv+kfQ7kyBhobFYuwZilKhFpDw6KyZp28yr4r1rL/8FRu29U8HAFCQIcQLdLJQ0gIfY25Uu5ZkGUotTJbYh0YCq8RvGE68+FqEtaZGV+Smb+sg0p4tcNnxjkgI5JB8AIyinLwMcyC+a3YKjjN9iAeb282fyNWPLPj13ljfCWezFdlkCLh9oYovMg+f/nc41jZFH+rNDPb1Tlth4Qo05q+BAQjx6mG6p3H9uoUwo22pJMqglYh4gH/JuUvkSkzaasiGcs+EReTy3QqAqCRHB57qMzWkKmfHJHYeA7Pph1onpsw+VzS1UnKudqmZw1JDgsMxCC09f4ZTa6WouRyNz4WwwOOfI57ZIoG/EdC9IpHar1qlKHOasX3Zaoa6LBzyZhPoZpvAh1OJvnlJlWt6lvln/7lfU/G90nv7DHFjL9151iYXBS0vCCAhz7ENLuev+eNaOsa7VApnAsE2Wc7Wu2pgJolHecVaYKdBzfyZz7acz4U2TbRGbmPYhf9ngzi2tt/WLItHj0h8vj8+Z7cEXYo0nl6L2zHhiFT1OXTUkw9UubRpNCcoRLsYJ2pwPT6XXP3PGcPL/0MLQY4UDyHVj7+qFo4NeynQUU2HAmUBet2eco+IdUWz6605dte3N5VsQDMcznyZ2mCt2RgORGpdcXqIdvfxck3xLE4bbwS88p6JkanKnQ3z4RBtddTGyKdYrow3qdgRtsLEjOuS8t70tEEDf18P0xQlKLUa3YRuUyT+SCOesgOI69fp/4yD8PGc3HRG2cX7VVLIIymoXkOXLXvjFlcsexIwLHLJfDtp0H4/hi+XD8WCRNC5YzZwkSZ3d+/d2/Xtmnyy3GhLM6Qo17sM35AjcXlsFI6s9eoRkZ9YWoeuU43fo9E0qmRSIv7ZU/kVV5rPZxgdFiJ8haMjYGL6MJOdNANXYfkhlXisK38D1BLBwj547z9zwMAAEENAABQSwECFAAUAAgICAC2ooZK+eO8/c8DAABBDQAABwAAAAAAAAAAAAAAAAAAAAAAdXNlci5qc1BLBQYAAAAAAQABADUAAAAEBAAAAAA= does not equal undefined"] (WARNING: The server did not provide any stacktrace information)
Command duration or timeout: 0 milliseconds
Build info: version: '3.3.1', revision: '5234b32', time: '2017-03-10 09:04:52 -0800'
System info: host: 'acbc328a495b.xxxxxxxxxxx.com', ip: '192.168.1.15', os.name: 'Mac OS X', os.arch: 'x86_64', os.version: '10.11.6', java.version: '1.8.0_121'
Driver info: driver.version: SeleniumWebDriver

same code as in above msg.

@dswbx
Copy link

dswbx commented Jul 4, 2017

I'm desperately trying to get firefox working on using a proxy... I've tried it with Firefox 54, 47.0, 47.0.1 and ESR. Using the code which @OndraM provided (and many more variations):

<?php
use WebDriver\Selector\SelectorCSS;
use Facebook\WebDriver\Remote\WebDriverCapabilityType;
use Facebook\WebDriver\Remote\RemoteWebDriver;
use Facebook\WebDriver\Remote\DesiredCapabilities;

require_once(__DIR__ . '/../vendor/autoload.php');

list($scriptname, $proxyIp, $proxyPort) = $argv;
//...
$wd_host = 'http://localhost:4444/wd/hub';

$capabilities = DesiredCapabilities::firefox();
$capabilities->setCapability(
    'requiredCapabilities',
    [
        WebDriverCapabilityType::PROXY => [
            'proxyType' => 'MANUAL',
            'httpProxy' => $proxyIp,
            'httpProxyPort' => $proxyPort,
            'sslProxy' => $proxyIp,
            'sslProxyPort' => $proxyPort,
        ],
    ]
);

$driver = RemoteWebDriver::create($wd_host, $capabilities);
//...
$driver->quit();

Always getting my own IP instead of proxy IP... Using facebook/web-driver @1.4.1 with PHP v7, geckodriver 0.17.0 and selenium v3.4. Works with Chrome.

@OndraM
Copy link
Collaborator

OndraM commented Jul 21, 2017

The firefox ESR (respectively the previous ESR, Based on Firefox 47) or Firefox 47.0.1 definitely works as expected, I personally use it :).

$capabilities = DesiredCapabilities::firefox();
$capabilities->setCapability(
    WebDriverCapabilityType::PROXY,
    [
        'proxyType' => 'manual',
        'httpProxy' => 'proxy.foo.bar:8118',
        'sslProxy' => 'proxy.foo.bar:8118',
    ]
);

However, Firefox 48+ is a different story. And I confirm I did not manage to get it working with latest Firefox 54, Geckodriver 18.0 and Selenium 3.4.0. There appears to be some issue with Selenium/Geckodriver, see mozilla/geckodriver#669

Furthermore, the WebDriver specification has changed recently (like few days ago - w3c/webdriver#964), and the port will again be part of the httpProxy / sslProxy property (like is used to be previously). So I assume Geckodriver will soon follow the spec (see https://bugzilla.mozilla.org/show_bug.cgi?id=1370959). So in the end, it should work the same way as is used to work in old Firefox version. However, not yet :-(.

Closing for now, because unfortunately nothing can be done from php-webdriver side - the solution is up to Mozilla / Selenium. So if you need proxy, I'm afraid you have to use the old Firefox version (47.0.1), or temporarily use Chromedriver, until a fix in Geckodriver will be done.

@OndraM OndraM closed this as completed Jul 21, 2017
@OndraM
Copy link
Collaborator

OndraM commented Aug 4, 2017

FYI the port issue is being worked on here: https://bugzilla.mozilla.org/show_bug.cgi?id=1369827

@Ajanth
Copy link

Ajanth commented May 21, 2018

@OndraM I'm trying to setup proxy with Firefox 47.0.1 and used your code snippet,
The proxy server needs authentication, I'm not sure how to pass credentials as I couldn't find a working example online but I've tried all methods. Following is my code

$this->capabilities->setCapability(
WebDriverCapabilityType::PROXY,
array(
'proxyType' => 'manual',
'httpProxy' => 'http://proxy.com:22225',
'sslProxy' => 'http://proxy.com:22225',
'ftpProxy' => 'http://proxy.com:22225',
 'socksUsername' => 'username',
 'socksPassword' => 'password'
));
$this->capabilities->setCapability(
WebDriverCapabilityType::PROXY,
array(
'proxyType' => 'manual',
'httpProxy' => 'http://username:[email protected]:22225',
'sslProxy' => 'http://username:[email protected]:22225',
'ftpProxy' => 'http://username:[email protected]:22225'
));

Nothing works for me. I'm trying to run from a Linux machine and following are the docker commands I used to start selenium grid and firefox node,

docker run -d -p 4444:4444 --name selenium-hub selenium/hub:latest
docker run -d --name selenium-node-firefox --link selenium-hub:hub selenium/node-firefox:2.53.1

greatly appreciate any help,

Thanks.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

7 participants