undetected-chromedriver icon indicating copy to clipboard operation
undetected-chromedriver copied to clipboard

Installing extension into V2

Open rwguerra opened this issue 3 years ago • 14 comments

Hello guys!

Im trying to add extension into V2 but its not working... when I do using "V1" it works properly

How can I put it to work?

This is the "v1" code that works

import undetected_chromedriver as uc
chrome_options = uc.ChromeOptions()
chrome_options.add_extension(PATH_TO_EXTENSION.crx)
driver = uc.Chrome(options=chrome_options)

This is the v2 code that DOSNT work

import undetected_chromedriver.v2 as uc
chrome_options = uc.ChromeOptions()
chrome_options.add_extension(PATH_TO_EXTENSION.crx)
driver = uc.Chrome(options=chrome_options)

rwguerra avatar Nov 02 '21 15:11 rwguerra

Is is possible to post the error message and some other pertinent details(software versions, system) to attempt a simulation of your problem?

nhwalkman avatar Nov 09 '21 17:11 nhwalkman

I have the same issue attempting to install a Webrtc blocker. Here is my snippet:

import seleniumwire.undetected_chromedriver.v2 as uc
options = uc.ChromeOptions()
options.add_argument('--no-first-run --no-service-autorun --password-store=basic')
options.add_argument('--data-path={}'.format(os.getcwd() + '/chrome-data/data-path'))
chrome_options.add_extension(webrtc_blocker.crx)
driver = uc.Chrome(options=options)

This is the environment I use:

  • Python 3.8
  • Windows 10
  • Chromium 94

There are no errors. The extension just doesnt install anymore

RedGlare96 avatar Nov 15 '21 13:11 RedGlare96

I can confirm. Works in vanilla chrome driver and v1. Not v2. I can see it passed in chrome options when loading. Looking into the code to see if I can see where/how it is getting dropped.

jglorioso avatar Nov 17 '21 15:11 jglorioso

Had to fallback to v1 too. Any news?

p.s. this repo is some impressing work. Does anybody knows where I can donate? I didn't find any reference

sorre97 avatar Nov 18 '21 10:11 sorre97

used --load-extension in arguments

Bug here v2.py:300

temporal fix

https://stackoverflow.com/questions/20782557/load-unpacked-chrome-extension-programmatically

baddiamond avatar Nov 29 '21 07:11 baddiamond

I have the same issue @ultrafunkamsterdam

FranciscoPalomares avatar Dec 07 '21 15:12 FranciscoPalomares

I just had some time to come back to this and have had little success getting it to work in v2 still. I went back to try to look at all commits since v1 to see what might have changed and it is quite a lot. In that time, @ultrafunkamsterdam has done extensive work.

I noticed this comment on the original 3.0 PR suggesting it has something to do with the new way the user profile directory is handled, but so far even forcing the extension in that directory gets it picked up, i.e. I can see the encoded bytes passed in with goog:chromeOptions when launching, but it does not register in the browser when it opens.

My use case is that I am trying to install a webrtc blocker so that it is not apparent that we are running on a proxy and the local ip is not leaked.

@ultrafunkamsterdam I know you are very busy, but if you have any guidance about what specifically changed to prevent extensions from working in v2, your guidance would be greatly appreciated!

jglorioso avatar Dec 09 '21 14:12 jglorioso

+1 I have the same issue @ultrafunkamsterdam

zxl777 avatar Dec 24 '21 03:12 zxl777

used --load-extension in arguments

Bug here v2.py:300

temporal fix

https://stackoverflow.com/questions/20782557/load-unpacked-chrome-extension-programmatically

Hello, can you kindly elaborate how to it works with "used --load-extension in arguments"? I used the following code, doesn't seem to install the browser extension. no error though.

options.add_argument('--load-extension = C:\Code\project_MP\abc.crx')

vancouverjackluo avatar Dec 25 '21 03:12 vancouverjackluo

+1 I have the same issue.

andreslopezferro avatar Dec 27 '21 06:12 andreslopezferro

used --load-extension in arguments Bug here v2.py:300 temporal fix https://stackoverflow.com/questions/20782557/load-unpacked-chrome-extension-programmatically

Hello, can you kindly elaborate how to it works with "used --load-extension in arguments"? I used the following code, doesn't seem to install the browser extension. no error though.

options.add_argument('--load-extension = C:\Code\project_MP\abc.crx')

I tried this as well and it gives me an error that the extension can not be loaded and or is missing a manifest file.. The same extension works with the vanilla chrome driver but installing it does not work on v1 and v2. I can however install the same extension through the chrome store and it works in v1 browser. I'm trying to automate the install as well

edit: figured it out for v1...

  1. Download the extension source. e.g: https://github.com/MetaMask/metamask-extension/releases Use the chrome settings
  2. extract the zip to some directory
  3. Load the directory (do not use an absolute path to a .crx file, that did not work for me)
import undetected_chromedriver as uc
chrome_options = uc.ChromeOptions()
chrome_options.add_argument('--load-extension=/Users/kpearson/Programs/misc/selenium/metamask-chrome-10.8.2')

self.driver = uc.Chrome(
    version=96,
    options=chrome_options)

pearsonkyle avatar Jan 09 '22 16:01 pearsonkyle

@pearsonkyle How do you use v1? It seems like v1 can no longer be used, because "import undetected_chromedriver as uc" is the same now as "import undetected_chromedriver.v2 as uc"

MacMarde avatar Apr 14 '22 14:04 MacMarde

issue still exists

ahmedmani avatar May 29 '22 00:05 ahmedmani

Owner @ultrafunkamsterdam replied with this in another issue:

  • "No. Extensions do not work in combination with remote debugging (which is used by this module).".
  • Then they said: "You can definitly add extensions. But you'll need a steady profile as extensions are kept in the profile."

Do extensions work or no!?

hamizi-ikram avatar Jun 14 '22 11:06 hamizi-ikram

Same issue here...my use case requires the metamask extension and I am not sure how I can load that into the uc driver... (works fine with standard selenium chromedriver)

ECHO-ECHOOooo avatar Oct 12 '22 23:10 ECHO-ECHOOooo

import undetected_chromedriver.v2 as uc

  1. Unpack your .crx file into default folder
  2. opts = uc.ChromeOptions()
  3. opts.add_argument("--load-extension=/Path/To/Your/Extention/Folder")
  4. driver = uc.Chrome(options=opts)

asinchenko avatar Oct 20 '22 07:10 asinchenko

Any idea how to add more than 1 extension? with this option "opts.add_argument("--load-extension=/Path/To/Your/Extention/Folder")" it's only possible to add 1 extension

xploader avatar Dec 26 '22 18:12 xploader

I actually had 2 extensions in my app. So it should be possible. Just try to add them one after another

"opts.add_argument("--load-extension=/Path/To/Your/Extention1/Folder")"
"opts.add_argument("--load-extension=/Path/To/Your/Extention2/Folder")"

asinchenko avatar Dec 27 '22 06:12 asinchenko

Are you sure it's working for you? When I tried your example it loaded just the last argument ("opts.add_argument("--load-extension=/Path/To/Your/Extention2/Folder")")

xploader avatar Dec 27 '22 10:12 xploader

Sorry for being a bit confusing. Sure, i did it, but unfortunately i can not find where my code is. I also suggest you to try this way: opts.add_argument("--load-extension=/path/to/Extension/,/path/to/Extension2/")

asinchenko avatar Dec 27 '22 12:12 asinchenko

Sorry for being a bit confusing. Sure, i did it, but unfortunately i can not find where my code is. I also suggest you to try this way: opts.add_argument("--load-extension=/path/to/Extension/,/path/to/Extension2/")

tested it .. not working. Thanks for trying to help!

xploader avatar Dec 27 '22 13:12 xploader

Found some code. Which opens google chrome using undetected chromedriver. (only had to update webdriver to 108 version). I can share my code of init_driver function where i upload those extensions

def init_driver(browser):
    screen_width = 1700
    screen_height = 700 if int(browser) > 10 else 0
    ua = "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/46.0.2486.0 Safari/537.36 Edge/13.10586"
    opts = uc.ChromeOptions()
    opts.add_argument("--window-size=150,700")
    opts.add_argument("--disable-blink-features=AutomationControlled")
    #opts.add_argument("--disable-features=UserAgentClientHint")
    opts.add_argument("--user-agent="+ua)
    opts.add_argument("--load-extension=./../TamperMonkey/,./../Browsec/")
    opts.add_argument("--ignore-certificate-errors")
    opts.add_argument("--disable-site-isolation-trials")
    opts.add_experimental_option('prefs', {
    'enable_do_not_track': True
    })
    driver = uc.Chrome(options=opts, subprocess=True, driver_executable_path=driverpath)
    driver.get('chrome-extension://'+tampermonkey+'/options.html#nav=new-user-script+editor')
    original_window = driver.current_window_handle
    return driver, original_window

Screen Shot 2022-12-27 at 19 41 31

asinchenko avatar Dec 27 '22 13:12 asinchenko

Ok, I got it. Thank you for your help!

xploader avatar Dec 27 '22 17:12 xploader

Did anyone found a option to load two extensions at same time ?

I have 1 metamask extension and 1 for my private proxy (its password protected so have to use extension to enter password)

I am able to add 2 extensions in Undected Chrome in normal one its running fine but not in undected chrome

byte-aroo avatar Jan 12 '23 19:01 byte-aroo

Did anyone found a option to load two extensions at same time ?

I have 1 metamask extension and 1 for my private proxy (its password protected so have to use extension to enter password)

I am able to add 2 extensions in Undected Chrome in normal one its running fine but not in undected chrome

If someone is facing the same problem you can chain multiple extensions at the same time (Notice the ",") : opts.add_argument("--load-extension=./ext1,./ext2")

Using this is not working for me (only the first one is loaded) : opts.add_argument("--load-extension=./ext1") opts.add_argument("--load-extension=./ext2")

JoffreyB31 avatar Sep 08 '23 10:09 JoffreyB31

找到一些代码。这会使用未检测到的浏览器驱动程序打开谷歌浏览器。(只需要将网络驱动程序更新到 108 版本)。我可以在上传这些扩展名的地方分享我的init_driver函数代码

def init_driver(browser):
    screen_width = 1700
    screen_height = 700 if int(browser) > 10 else 0
    ua = "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/46.0.2486.0 Safari/537.36 Edge/13.10586"
    opts = uc.ChromeOptions()
    opts.add_argument("--window-size=150,700")
    opts.add_argument("--disable-blink-features=AutomationControlled")
    #opts.add_argument("--disable-features=UserAgentClientHint")
    opts.add_argument("--user-agent="+ua)
    opts.add_argument("--load-extension=./../TamperMonkey/,./../Browsec/")
    opts.add_argument("--ignore-certificate-errors")
    opts.add_argument("--disable-site-isolation-trials")
    opts.add_experimental_option('prefs', {
    'enable_do_not_track': True
    })
    driver = uc.Chrome(options=opts, subprocess=True, driver_executable_path=driverpath)
    driver.get('chrome-extension://'+tampermonkey+'/options.html#nav=new-user-script+editor')
    original_window = driver.current_window_handle
    return driver, original_window

屏幕截图 2022-12-27 在 19 41 31

this work for me !

mIgLLL avatar Sep 09 '23 10:09 mIgLLL