Skip to content

Cannot add unpacked extension on Ubuntu VPS #2334

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

Closed
iamumairayub opened this issue Dec 3, 2023 · 1 comment
Closed

Cannot add unpacked extension on Ubuntu VPS #2334

iamumairayub opened this issue Dec 3, 2023 · 1 comment
Labels
invalid usage You may need to change what you're doing question Someone is looking for answers UC Mode / CDP Mode Undetected Chromedriver Mode / CDP Mode

Comments

@iamumairayub
Copy link

I am trying to add an extension but script fails to run. When I comment out extension_dir line it works fine, but that is not what I want.

I same script on Windows headed and it works just fine.

from selenium import webdriver
from selenium.webdriver.chrome.options import Options
from concurrent import futures

from seleniumbase import Driver

def run_session(profile_id):

    try:

        chrome_options = Options()

        chrome_options.add_argument('--headless=new')
        print(chrome_options.to_capabilities())

        driver = Driver(
            cap_string=chrome_options.to_capabilities(),
            uc=True, 
            extension_dir=r'/home/NopeCHA-CAPTCHA-Solver',
        )

        driver.get("http://lumtest.com/myip.json")
        print(driver.page_source)

        return 'finished'

    except:
        return traceback.format_exc()
    

with futures.ThreadPoolExecutor(max_workers=5) as executor:

    all_jobs = []
    for profile_id in (1,2,3):
        job = executor.submit(
            run_session, 
            profile_id,
        )
        all_jobs.append(job)

    for future in futures.as_completed(all_jobs):
        print('Run completed: {}'.format(future.result()))

I get this error when I run above code.

(The process started from chrome location /usr/bin/google-chrome is no longer running, so ChromeDriver is assuming that Chrome has crashed

Tried this, script runs, but no extension is added.

def run_session(profile_id):

    chrome_options = Options()

    chrome_options.add_argument('--headless=new')
    chrome_options.add_argument(r'--load-extension=/home/NopeCHA-CAPTCHA-Solver')

    print(chrome_options.to_capabilities())

    driver = Driver(
        cap_string=chrome_options.to_capabilities(),
        uc=True, 
    )

    driver.get("chrome://extensions/")
    print(driver.page_source)
    driver.save_screenshot('test.png')
Distributor ID: Ubuntu
Description:    Ubuntu 20.04.5 LTS
Release:        20.04
Codename:       focal

python -V
Python 3.10.7

>>> import seleniumbase
>>> seleniumbase.__version__
'4.21.4'
@mdmintz mdmintz added question Someone is looking for answers invalid usage You may need to change what you're doing UC Mode / CDP Mode Undetected Chromedriver Mode / CDP Mode labels Dec 3, 2023
@mdmintz
Copy link
Member

mdmintz commented Dec 3, 2023

The cap_string is only for remote Selenium Grid use. (Remote Selenium Grids don't support UC Mode because SeleniumBase can't directly control the internals of drivers on remote machines.)

Use the built-in args for changing Chrome options. There's already a headless2 arg for using Chrome's newer headless mode:

headless2=None, # Chromium's new headless mode. (Has more features)

For your case, you may need to also a virtual display on Linux: https://github.com/mdmintz/sbVirtualDisplay (This is because you're using the Driver() format instead of the SB() or BaseCase formats, which handle virtual displays automatically.)

For your case on Linux, try:

from seleniumbase import Driver
from sbvirtualdisplay import Display

with Display(visible=0, size=(1440, 1880)):
    driver = Driver(uc=True, headless2=True, extension_dir='/home/NopeCHA-CAPTCHA-Solver'

Also, multithreaded SeleniumBase tests are only supported with pytest via pytest-xdist. (Eg. pytest -n5)
(ThreadPoolExecutor isn't supported). Details here:
#2006 (comment) and #2196 (comment)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
invalid usage You may need to change what you're doing question Someone is looking for answers UC Mode / CDP Mode Undetected Chromedriver Mode / CDP Mode
Projects
None yet
Development

No branches or pull requests

2 participants