webfp / tor-browser-selenium

Tor Browser automation with Selenium.
MIT License
528 stars 101 forks source link

Geckodriver is unavailable if all ports are closed by default #177

Closed ghost closed 1 year ago

ghost commented 1 year ago

By default tbselenium creates selenium.webdriver.firefox.service.Service without specifying port, which makes the Service object connect gecko to a random free port on localhost. It is a problem in Tails, where all localhost ports, except Tor ports (9001, etc.), are closed by default. There is a possibility to accept connection to a particular port via iptables, but it becomes tricky if the port is always random.

I suggest the following:

  1. Add gecko port to TorBrowserDriver.__init__() arguments:

https://github.com/webfp/tor-browser-selenium/blob/98c2bd5bdf1c83bd2c54cb0ba936b1b35647315c/tbselenium/tbdriver.py#L27

  1. Specify gecko port for the Service object:

https://github.com/webfp/tor-browser-selenium/blob/98c2bd5bdf1c83bd2c54cb0ba936b1b35647315c/tbselenium/tbdriver.py#L79

https://github.com/webfp/tor-browser-selenium/blob/98c2bd5bdf1c83bd2c54cb0ba936b1b35647315c/tbselenium/tbdriver.py#L85

gunesacar commented 1 year ago

Thanks for the suggestion @regnveig. Let me know how the following looks like: https://github.com/webfp/tor-browser-selenium/compare/custom_geckodriver_port?expand=1

The choice of default 0 is based on: https://github.com/SeleniumHQ/selenium/blob/40c16bb016f979a5ba327f75c8c0f60138f2fbbe/py/selenium/webdriver/firefox/service.py#L38-L40

ghost commented 1 year ago

@gunesacar, thank you! It looks much better than the fix I used. I guess it's pretty good to merge!

gunesacar commented 1 year ago

I've merged these changes into main and made a release on PyPI. Thanks for the suggestion, @regnveig.