GithubHelp home page GithubHelp logo

webfp / tor-browser-selenium Goto Github PK

View Code? Open in Web Editor NEW
517.0 25.0 100.0 454 KB

Tor Browser automation with Selenium.

License: MIT License

Python 98.07% Shell 0.89% HTML 1.05%
selenium tor-browser tor automation stem

tor-browser-selenium's People

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

tor-browser-selenium's Issues

The torrc file is missing and could not be created.

Hello receive this error upon launching tor through this.

The torrc file is missing and could not be created.

When I manually run the torbrowser from command line it works fine Before I provide the massive amounts of logs I have , is this a known issue? Is there anything I can do?

Let me know if you want the runtime logs,

Thanks
I am just using the basic example on the site.

from tbselenium.tbdriver import TorBrowserDriver
with TorBrowserDriver("/path/to/myBundle/") as driver:
    driver.get('https://check.torproject.org')

Stem can't be imported on CI

We get the following import error for Stem on CI when try to import from stem.control import Controller :

No module named stem.control

At the same time logs say Successfully installed stem-1.4.0
Travis log: https://travis-ci.org/webfp/tor-browser-selenium/builds/122708529

$ sudo -H pip install stem
Collecting stem
/usr/local/lib/python2.7/dist-packages/pip/_vendor/requests/packages/urllib3/util/ssl_.py:90: InsecurePlatformWarning: A true SSLContext object is not available. This prevents urllib3 from configuring SSL appropriately and may cause certain SSL connections to fail. For more information, see https://urllib3.readthedocs.org/en/latest/security.html#insecureplatformwarning.
  InsecurePlatformWarning
  Downloading stem-1.4.0.tar.bz2 (1.6MB)
    100% |████████████���███████████████████| 1.6MB 365kB/s 
Building wheels for collected packages: stem
  Running setup.py bdist_wheel for stem
  Stored in directory: /root/.cache/pip/wheels/80/6d/23/2db8210a00ee425efa4f31f4d374214e5325a26901ae57f64a
Successfully built stem
Installing collected packages: stem
Successfully installed stem-1.4.0
/usr/local/lib/python2.7/dist-packages/pip/_vendor/requests/packages/urllib3/util/ssl_.py:90: InsecurePlatformWarning: A true SSLContext object is not available. This prevents urllib3 from configuring SSL appropriately and may cause certain SSL connections to fail. For more information, see https://urllib3.readthedocs.org/en/latest/security.html#insecureplatformwarning.
  InsecurePlatformWarning
You are using pip version 7.1.2, however version 8.1.1 is available.
You should consider upgrading via the 'pip install --upgrade pip' command.

TBB path issue

I'm having some issues with the basic usage path if someone can assist.

from tbselenium.tbdriver import TorBrowserDriver
with TorBrowserDriver("/path/to/TorBrowserBundle/") as driver:
driver.get('https://check.torproject.org')

/path/to/TorBrowserBundle/ << what should it be exactly.

My TorBrowser is installed in C:\Test software\Tor Browser, I've tried that directory and in addition I've tried "C:\Test software\Tor Browser\Browser" and "C:\Test software\Tor Browser\Browser\firefox.exe". Please clarify this part.

Environment variable `TBB_PATH` can't be found.

Hi,

I have installed tbselenium, geckodriver and TBB as required, but when I try first basic usage:

from tbselenium.tbdriver import TorBrowserDriver
with TorBrowserDriver("C:/Users/msagovac/Desktop/Tor Browser") as driver:
    driver.get('https://check.torproject.org')

I got an error:
Environment variable TBB_PATH can't be found.
I am not sure what should be TorBrowserBundle path. Try many alternatives.

I ma using Python 3 on Windows

Can't read cookies

Hello!

I'm working on some stuff for SecureDrop, and it looks like maybe tbselenium can't read cookies, using driver.get_cookies().

I can set cookies using driver.add_cookies(), and read them back - but when I see a Cookie header in tcpdump, I can't read the cookie in question.

This could well be a problem with the test setup for SecureDrop - I don't have a minimal example, but I'll work on one.

Thanks!

Improve the interface to take screenshots

Currently, if a user wants to take screenshots of the pages visited with the driver, he will need to add all the URLs as exceptions using the class method TorBrowserDriver.add_exception() before instantiating the TorBrowserDriver.

Adding an exception means granting permissions to a domain to access the Canvas, otherwise restricted by the TorBrowser to protect against browser fingerprinting. Selenium requires access to the Canvas to take the screenshot. However, the changes we commit to permissions.sqlite do not have any effect when the browser is running (probably the database is loaded into memory by Firefox).

The aim of this ticket is to improve the interface for taking screenshots so that users do not need to add an exception for each future visit beforehand. We need to investigate if there is a way to refresh the permissions loaded in the browser on runtime.

Can't setup TBB paths on macOS

I'm using these parameters for TorBrowserDriver():

tbb_fx_binary_path='/Applications/TorBrowser.app/Contents/MacOS/firefox',
tbb_profile_path='/Users/tommaso/Library/Application Support/TorBrowser-Data/Browser/52e8j7wk.default',
tor_cfg=cm.USE_RUNNING_TOR,
socks_port=7000,
control_port=cm.STEM_CONTROL_PORT

I get the following error:

Traceback (most recent call last):

  File "/Users/tommaso/repos/anon_visits/anon_visits.py", line 6, in <module>
    main()
  File "/Users/tommaso/repos/anon_visits/com/reloadcom/anonvisits/main.py", line 20, in main
    raise exc
  File "/Users/tommaso/repos/anon_visits/com/reloadcom/anonvisits/main.py", line 14, in main
    browser = TorBrowser()
  File "/Users/tommaso/repos/anon_visits/com/reloadcom/anonvisits/tor_browser.py", line 19, in __init__
    control_port=cm.STEM_CONTROL_PORT
  File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/tbselenium/tbdriver.py", line 44, in __init__
    tbb_profile_path, tor_data_dir)
  File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/tbselenium/tbdriver.py", line 139, in setup_tbb_paths
    chdir(self.tbb_browser_dir)
FileNotFoundError: [Errno 2] No such file or directory: 'Browser'

I thought the first parameter (tbb_path) was optional, but then you join() it with 'Browser' and try to change the directory inside it (chdir()) which is raising the error because it tries to cd into './Browser/' I think.

How can I fix this, and start TBB on macOS? I'm not too sure what each path parameter shoud be

include test modules in tbselenium

When I install tbselenium using pip I can't import the fixtures.py module or any other module in test/. It would be useful for tbselenium users to include them.

Tor Launches But Won't Get Page

I'm able to get the Tor browser to launch but sending the get command does nothing. I have checked that I am able to use Tor outside of calling it via Selenium and it works fine. If I wait long enough I get a connection refused message

Traceback (most recent call last): File "<stdin>", line 1, in <module> File "/home/user/tor-browser-selenium/tbselenium/tbdriver.py", line 57, in __init__ log_path=tbb_logfile_path) File "/usr/local/lib/python3.5/dist-packages/selenium/webdriver/firefox/webdriver.py", line 154, in __init__ keep_alive=True) File "/usr/local/lib/python3.5/dist-packages/selenium/webdriver/remote/webdriver.py", line 151, in __init__ self.start_session(desired_capabilities, browser_profile) File "/usr/local/lib/python3.5/dist-packages/selenium/webdriver/remote/webdriver.py", line 240, in start_session response = self.execute(Command.NEW_SESSION, parameters) File "/usr/local/lib/python3.5/dist-packages/selenium/webdriver/remote/webdriver.py", line 308, in execute self.error_handler.check_response(response) File "/usr/local/lib/python3.5/dist-packages/selenium/webdriver/remote/errorhandler.py", line 194, in check_response raise exception_class(message, screen, stacktrace) selenium.common.exceptions.WebDriverException: Message: connection refused

Python 3.5.2, Selenium 3.8, Gecko 0.17.0
Tor 7.0.10, Linux Mint 18.1 (Ubuntu 16.04)

How to authenticate tor controller using password

When using TorBrowserDriver(tor_cfg=cm.USE_RUNNING_TOR) can it connect to the tor process, when a password is set for the controller connection?
If yes, how should i pass the password for the authentication to the TorBrowserDriver()?

./run_tests.py "Could not find firefox in your system PATH."

vagrant@jessie-amd64:/vagrant/tor-browser-crawler/tor-browser-selenium$ ./run_tests.py /vagrant/tor-browser_en-US
......s...s.sssssEE.......EEEEEEEEEE

ERROR: test_screen_capture (test_tbdriver.ScreenshotTest)
Make sure we can capture the screen.

Traceback (most recent call last):
  File "/vagrant/tor-browser-selenium/tbselenium/test/test_tbdriver.py", line 153, in test_screen_capture
    canvas_exceptions=[cm.CHECK_TPO_URL]) as driver:
  File "tbselenium/tbdriver.py", line 56, in __init__
    timeout=60)
  File "/usr/local/lib/python2.7/dist-packages/selenium/webdriver/firefox/webdriver.py", line 67, in __init__
    firefox_options.binary_location = self.binary if isinstance(self.binary, basestring) else self.binary._get_firefox_start_cmd()
  File "/usr/local/lib/python2.7/dist-packages/selenium/webdriver/firefox/firefox_binary.py", line 163, in _get_firefox_start_cmd
    " Please specify the firefox binary location or install firefox")
RuntimeError: Could not find firefox in your system PATH. Please specify the firefox binary location or install firefox
[snip]

----------------------------------------------------------------------
Ran 36 tests in 35.725s

FAILED (errors=12, skipped=7)
vagrant@jessie-amd64:/vagrant/tor-browser-crawler/tor-browser-selenium$ find /vagrant/tor-browser_en-US  -name firefox
/vagrant/tor-browser_en-US/Browser/firefox
vagrant@jessie-amd64:/vagrant/tor-browser-crawler/tor-browser-selenium$ date && uname -a
Mon Apr 11 10:09:55 UTC 2016
Linux jessie-amd64 3.16.0-4-amd64 #1 SMP Debian 3.16.7-ckt9-2 (2015-04-13) x86_64 GNU/Linux
vagrant@jessie-amd64:/vagrant/tor-browser-crawler/tor-browser-selenium$ 

Don't keep state for TBB tor process

If we use the tor process in the TBB folder, we don't start with a new data directory and pollute the existing tor state files.

It should be possible to clone tor data dir into a fresh one, as we already do for Firefox profile.

Remove run_test.py

We could replace it with a py.test single liner.
We just need be able to accept command line arguments in conftest.py.

Travis CI tests break when using latest TBB

When using TBB 5.5.3 for the tests, Selenium cannot connect to the TorBrowser (Firefox) driver. The message error from Firefox logs points to a problem with glibc:

tor-browser_en-US/Browser/firefox: relocation error: ../tor-browser_en-US/Browser/firefox: symbol _ZNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEE9_M_createERmm, version GLIBCXX_3.4.21 not defined in file libstdc++.so.6 with link time reference

I am able to reproduce it running the tests on an Ubuntu 14.04. The problem goes away when using newer versions of Ubuntu, as they have a newer version of glibc that allows running the firefox binary in TBB. However, Travis only supports instances of Ubuntu up to 14.04.

I am using TBB 4.5.1 for now. Any suggestion on how to solve this problem?

FF can't find profile with relative TBB_PATH

If TBB_PATH is set to a relative path I get a popup error message from FF saying it can't find the profile. The issue is fixed by getting the absolute path of Browser directory. I'm going to send a PR in a minute.

Reduce test fragility

In majority of the tests, we load web pages over Tor network, which is not the most reliable transport.

We should look for ways to make tests more resilient, such as rerunning tests when the failure is due to the network.

Allow running TorBrowserDriver with the different tor binaries and configurations

We should allow users to pick which tor process they want to use:
1. Use tor running on a certain port: e.g. system tor daemon, non-daemon process started by the user
2. Start tor in the TBB directory: this is the default behavior of TB (torlauncher).
3. Start tor through Stem: allows custom torrc configs and more elaborate control over tor the process

Whenever I try to run any of the examples, I get a WebDriverException saying I can't load the profile.

Traceback (most recent call last):
  File "examples.py", line 3, in <module>
    with TorBrowserDriver("/home/me/Downloads/tor-browser_en-US/") as driver:
  File "/home/me/Downloads/tor-browser_en-US/env/lib/python3.6/site-packages/tbselenium/tbdriver.py", line 59, in __init__
    timeout=cm.TB_INIT_TIMEOUT)
  File "/home/me/Downloads/tor-browser_en-US/env/lib/python3.6/site-packages/selenium/webdriver/firefox/webdriver.py", line 80, in __init__
    self.binary, timeout)
  File "/home/me/Downloads/tor-browser_en-US/env/lib/python3.6/site-packages/selenium/webdriver/firefox/extension_connection.py", line 52, in __init__
    self.binary.launch_browser(self.profile, timeout=timeout)
  File "/home/me/Downloads/tor-browser_en-US/env/lib/python3.6/site-packages/selenium/webdriver/firefox/firefox_binary.py", line 68, in launch_browser
    self._wait_until_connectable(timeout=timeout)
  File "/home/me/Downloads/tor-browser_en-US/env/lib/python3.6/site-packages/selenium/webdriver/firefox/firefox_binary.py", line 108, in _wait_until_connectable
    % (self.profile.path))
selenium.common.exceptions.WebDriverException: Message: Can't load the profile. Profile Dir: /tmp/tmpiu_7hssx/webdriver-py-profilecopy If you specified a log_file in the FirefoxBinary constructor, check it for details.

I can now see that the error was mentioned here, under troubleshooting: https://github.com/webfp/tor-browser-selenium/blob/master/README.md
If there was any solution linked there, it's very unclear, at least to me. It looks like the Selenium version I'm using is 3.4.2, Python version I use is 3.6.

test_noscript_webgl_enabled broken w/ TBB 6.5

===================================================== FAILURES =====================================================
_____________________________________ NoScriptTest.test_noscript_webgl_enabled _____________________________________

self = <tbselenium.test.test_addons.NoScriptTest testMethod=test_noscript_webgl_enabled>

    @pytest.mark.skipif(cm.TRAVIS, reason="CI doesn't support WebGL")
    def test_noscript_webgl_enabled(self):
        """Make sure that when we disable NoScript's WebGL blocking,
            WebGL becomes available. This is to the test method we
            use in test_noscript is sane.
            """
        disable_NS_webgl_pref = {"noscript.forbidWebGL": False}
        with TBDriverFixture(TBB_PATH,
                             pref_dict=disable_NS_webgl_pref) as driver:
            driver.load_url_ensure(cm.CHECK_TPO_URL, wait_for_page_body=True)
            webgl_support = driver.execute_script(self.WEBGL_CHECK_JS)
>           self.assertIn("getSupportedExtensions", webgl_support)
E           TypeError: argument of type 'NoneType' is not iterable

/home/fowlslegs/src/fowlslegs/tor-browser-selenium/tbselenium/test/test_addons.py:67: TypeError
====================================== 1 failed, 45 passed in 287.04 seconds =======================================

last_err not initialized

In fixtures.py, the variable last_err may be accessed without being initialized. It is safer to initialize it outside the try-except. I actually found the bug because the call inside on of the fixture's for loop raised an exception that it was not catched in the except. I'll be sending a PR soon.

Dont go to webadress

I tried the basic usage
with TorBrowserDriver("/home/blackturtle/Downloads/tor-browser-linux64-7.5.3_en-US/tor-browser_en-US/") as driver: driver.get('http://www.google.com')

It opens the webbrowser which is firefox but dont go to adresss?
Any suggestion
Thank you in Advance

Convert TBB related paths to absolute paths

In CI tests we pass TBB_PATH as a a relative path which was a major source of mismatch between the local tests and CI tests. We should convert paths to absolute paths as early as possible.

Expose Tor bootstrap status/errors

When tor-browser-selenium is asked to start a Tor process and Tor cannot bootstrap, we get a cryptic error from Selenium:

Can't load the profile. Profile Dir: /tmp/tmpxyz/webdriver-py-profilecopy If you specified a log_file in the FirefoxBinary constructor, check it for details

@mjuarezm proposed that it could be useful to expose Tor bootstrap errors and/or status to callers.

WebDriverException: Can't load the profile.

WebDriverException: Can't load the profile. Profile Dir: /tmp/tmp_rzsi126/webdriver-py-profilecopy If you specified a log_file in the FirefoxBinary constructor, check it for details.

This occurs after i do:

from tbselenium.tbdriver import TorBrowserDriver
with TorBrowserDriver("/storage/programfiles/tor-browser_en-US") as driver:
    driver.get('www.reddit.com')

Any idea on how to solve this? :)

Something wrong with pars_args()

Using this example, I found a problem in def main()

def main():
    desc = "Visit check.torproject.org website"
    parser = ArgumentParser(description=desc)
    parser.add_argument('TBB_PATH')
    args = parser.parse_args()
    visit(args.tbb_path)

In line args = parser.parse_args() I got an error:

the following arguments are required: TBB_PATH

in py3.4, and

error: too few arguments

in py2.7

If I try debugging step by step it raise:

args = parser.parse_args()
        ^
SyntaxError: invalid syntax

and

SystemExit: 2

TBB_PATH writed to environment variables
OS: Win10

FileNotFoundError: [Errno 2] No such file or directory: 'py.test': 'py.test'

Traceback (most recent call last):
File "./run_tests.py", line 25, in
"term-missing", "--durations=10", test_dir])
File "/usr/lib/python3.6/subprocess.py", line 267, in call
with Popen(*popenargs, **kwargs) as p:
File "/usr/lib/python3.6/subprocess.py", line 709, in init
restore_signals, start_new_session)
File "/usr/lib/python3.6/subprocess.py", line 1344, in _execute_child
raise child_exception_type(errno_num, err_msg, err_filename)
FileNotFoundError: [Errno 2] No such file or directory: 'py.test': 'py.test'

Invalid Firefox binary

Hi,
could you please give me an example of correct "tbb_fx_binary_path" for windows?
I have this error:
Traceback (most recent call last):
File "C:/Python36/Moje/webTest/Tor2.py", line 10, in
with TorBrowserDriver("I:\Tor\Tor Browser\") as driver:
File "C:\Python36\lib\site-packages\tbselenium\tbdriver.py", line 44, in init
tbb_profile_path, tor_data_dir)
File "C:\Python36\lib\site-packages\tbselenium\tbdriver.py", line 124, in setup_tbb_paths
% tbb_fx_binary_path)
tbselenium.exceptions.TBDriverPathError: Invalid Firefox binary I:\Tor\Tor Browser\Browser\firefox

Submit a package to PyPi

You should consider shipping this as wheel via PyPi. It would be easier to use as a dependency for people and there are no real alternatives for those wishing to drive Tor Browser with a Python module.

Connection Refused Error on initialising TorBrowserDriver object

Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/usr/local/lib/python3.6/dist-packages/tbselenium/tbdriver.py", line 57, in __init__
    log_path=tbb_logfile_path)
  File "/usr/local/lib/python3.6/dist-packages/selenium/webdriver/firefox/webdriver.py", line 158, in __init__
    keep_alive=True)
  File "/usr/local/lib/python3.6/dist-packages/selenium/webdriver/remote/webdriver.py", line 154, in __init__
    self.start_session(desired_capabilities, browser_profile)
  File "/usr/local/lib/python3.6/dist-packages/selenium/webdriver/remote/webdriver.py", line 243, in start_session
    response = self.execute(Command.NEW_SESSION, parameters)
  File "/usr/local/lib/python3.6/dist-packages/selenium/webdriver/remote/webdriver.py", line 311, in execute
    self.error_handler.check_response(response)
  File "/usr/local/lib/python3.6/dist-packages/selenium/webdriver/remote/errorhandler.py", line 237, in check_response
    raise exception_class(message, screen, stacktrace)
selenium.common.exceptions.WebDriverException: Message: connection refused

Also, the init function of the TorBrowserDriver class seems to be blocking, why is that so ?

TBB_PATH` can't be found

raise TBTestEnvVarError("Environment variable `TBB_PATH` can't be found.")

tbselenium.exceptions.TBTestEnvVarError: Environment variable TBB_PATH can't be found.
using windows btw
I try:
C:\Users\D1\Desktop\Tor Browser\Start Tor Browser.lnk

C:\Users\D1\Desktop\Tor Browser\Browser\firefox.exe

C:\Users\D1\Desktop\Tor Browser\Browser\TorBrowser\Tor\tor.exe

What am I missing here?

from tbselenium.tbdriver import TorBrowserDriver
with TorBrowserDriver("C:/Users/D1/Desktop/Tor Browser/Browser/orBrowser/Tor/tor.exe") as driver:
driver.get('https://check.torproject.org')

Unable to use bridges other than obfs4

The browser always initializes with obfs4 bridge when opened through the library. This happens even after I change it to any other bridge like meek-amazon and obfs4 takes long time to open.

Directly opening the browser takes the saved settings but when opened with tbselenium, the torrc file /home/olam/tor-browser_en-US/Browser/TorBrowser/Data/Tor/torrc is being overwritten.

Tor Bundle Version: 6.5.1

Remove xvfb related code

Starting and stopping a virtual display is shouldn't be done within TorBrowserDriver. It's rather caller's responsibility to manage xvfb.

Yet, we'd want to run tests using xvfb.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.