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

Cannot install extensions. #188

Closed
SheldonPatnett opened this issue Jun 11, 2023 · 9 comments
Closed

Cannot install extensions. #188

SheldonPatnett opened this issue Jun 11, 2023 · 9 comments

Comments

@SheldonPatnett
Copy link

How can you use extensions? It's not quite clear in tbdriver.py. I'm passing in a list of extensions ie
extensions = []
extensions.append('/DEU/workers/Browser/adblock_plus-3.17.xpi')

Then initializing the driver:

    self.driver = TorBrowserDriver(
        tbb_path=f'{BASE_DIR}',
        extensions=extensions,
        pref_dict=pref_dict,
        options=options
    )
@gunesacar
Copy link
Collaborator

Your code looks right. See also the test code in test_should_install_custom_extension for reference:

with TBDriverFixture(TBB_PATH, extensions=[xpi_path]) as driver:
assert 'Borderify' in self.get_list_of_installed_addons(driver)

If the problem persists, please check whether the options or pref_dict is interfering, and share the error message you get, if any.

@SheldonPatnett
Copy link
Author

Thank you for the speedy reply! The TBB_PATH used to launch the browser doesn't work, it says it needs proper path or binarary.. In the test.
In production I use 'workers' folder which has a subfolder of Browser which the current TOR browser bundle.

@SheldonPatnett
Copy link
Author

Sorry for not including my current unit test, please find it below

`import unittest
from os.path import dirname, realpath, join
from tbselenium.test.fixtures import TBDriverFixture
from tbselenium.test.test_addons import TBAddonsTest
from xvfbwrapper import Xvfb

vdisplay = Xvfb(width=1920, height=1080, colordepth=24)
vdisplay.start()

def start_tbselenium_with_adblock():
TBB_PATH = '/DEU/workers' # Replace with the actual TBB path
xpi_path = '/DEU/workers/Browser/adblock_plus-3.17.xpi'

with TBDriverFixture(TBB_PATH, extensions=[xpi_path]) as driver:
    addons_test = TBAddonsTest()
    assert 'Adblock Plus' in addons_test.get_list_of_installed_addons(driver)
    # Run other test methods from TBAddonsTest if needed

if name == "main":
start_tbselenium_with_adblock()`

addons_test.get_list_of_installed_addons(driver) throws the following exception
*** selenium.common.exceptions.WebDriverException: Message: Failed to extract web element from Marionette response

@SheldonPatnett
Copy link
Author

`from xvfbwrapper import Xvfb
vdisplay = Xvfb(width=1920, height=1080, colordepth=24)
vdisplay.start()
from os.path import dirname, realpath, join
from tbselenium.test.fixtures import TBDriverFixture
from tbselenium.test.test_addons import TBAddonsTest
import traceback

class CustomTBAddonsTest(TBAddonsTest):
def init(self):
super().init()
self.TBB_PATH = 'workers'

def test_should_install_custom_extension(self):
    try:
        with TBDriverFixture(self.TBB_PATH, extensions=['workers/Browser/adblock_plus-3.17.xpi']) as driver:
            import ipdb ; ipdb.set_trace()
            assert 'Borderify' in self.get_list_of_installed_addons(driver)
    except Exception as e:
        print("Error occurred during test execution:")
        print(traceback.format_exc())

test = CustomTBAddonsTest()
test.test_should_install_custom_extension()
`

Sorry, I wasn't instancing the class properly in my previous post. I'm able to do things like driver.get("https://google.com") at the breakpoint but when I call the self.get_list_of_installed_addons(driver) method I'm getting *** selenium.common.exceptions.WebDriverException: Message: Failed to extract web element from Marionette response

@gunesacar
Copy link
Collaborator

It's hard to understand the code due to formatting issues, but if you can load a page via driver.get but you get an error for get_list_of_installed_addons, I'd recommend updating geckodriver to 0.31.0 and selenium to latest.

@SheldonPatnett
Copy link
Author

I'm deeply sorry about the confusion. I really should learn Github formatting!

from xvfbwrapper import Xvfb
vdisplay = Xvfb(width=1920, height=1080, colordepth=24)
vdisplay.start()
from os.path import dirname, realpath, join
from tbselenium.test.fixtures import TBDriverFixture
from tbselenium.test.test_addons import TBAddonsTest
import traceback
from tbselenium.tbdriver import TorBrowserDriver
from selenium.webdriver.common.by import By

TBB_PATH = 'workers'
extensions = ['workers/Browser/adblock_plus-3.17.xpi', '/DEU/workers/Browser/ublock_origin-1.49.2.xpi']
driver = TorBrowserDriver("/DEU/workers", extensions=extensions)
driver.get("about:addons")
driver.save_screenshot('test.png')

Using snippets from your unit test, I was able to take a screenshot. The load_url method doesn't exists for some reason. The screenshot does indeed show the adblockers are installed, but I'm getting a low score on https://adblock-tester.com/ vs when I manually run it locally with extensions installed. This is most certainly out of scope for the this repository.

Thank you very much for you help :) Feel free to mark this issue as solved.

@SheldonPatnett
Copy link
Author

P.S. Is there a way I can buy you a coffee?

@SheldonPatnett
Copy link
Author

Maybe the extensions aren't able to run in the context of a private window? Which I believe TOR browsers launches in, by default?

@gunesacar
Copy link
Collaborator

Hi @SheldonPatnett , glad you have it worked.

Allowing extensions to run on Private windows is a good idea.
Trying them one by one may be another...
You can also compare the (adblocker) rulesets used in the browsers to see if the (ruleset) versions match or not.

But, as you said, this issue is likely not related to tor-browser-selenium. So I'm closing.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants