webfp / tor-browser-selenium

Tor Browser automation with Selenium.
MIT License
548 stars 100 forks source link

expose path tbb_browser_dir #210

Open milahu opened 3 months ago

milahu commented 3 months ago

on nixos linux tbb_browser_dir is renamed from Browser to tor-browser and all other paths are original

for example

$ ( cd /nix/store/sgixwgp3yf95dhi59661g2d11gh865vs-tor-browser-13.0.13/share && ls -d tor-browser/{firefox,fonts,TorBrowser,TorBrowser/Data/Browser/profile.default} )
tor-browser/firefox
tor-browser/fonts
tor-browser/TorBrowser
tor-browser/TorBrowser/Data/Browser/profile.default

so to avoid passing all paths to TorBrowserDriver i made all paths relative to tbb_browser_dir

so now i can call

tbb_browser_dir = "..."
with TorBrowserDriver(tbb_browser_dir=tbb_browser_dir) as driver:
    # ...

i hope this also works for other users ...

also fix #209

with this patch, i can package tbselenium.nix with

{
  # set default paths
  postPatch = ''
    substituteInPlace tbselenium/tbdriver.py \
      --replace \
        'GECKO_DRIVER_EXE_PATH = shutil.which("geckodriver")' \
        'GECKO_DRIVER_EXE_PATH = "${geckodriver}/bin/geckodriver"' \
      --replace \
        'DEFAULT_TBB_BROWSER_DIR = ""' \
        'DEFAULT_TBB_BROWSER_DIR = "${tor-browser}/share/tor-browser"' \
  '';

with these default paths TorBrowserDriver works without any args

with TorBrowserDriver() as driver:
    driver.get("https://httpbin.org/ip")

os.chdir is not necessary torbrowser already uses tbb_browser_dir as workdir this is why tbb_browser_dir must be writable probably to write .config/ and .tor project/

gunesacar commented 3 months ago

https://github.com/webfp/tor-browser-selenium/issues/209#issuecomment-2194051090