4

All my efforts to open chrome browser with Browsec extension enabled are failing. Here is what i tried in last -

# Configure the necessary command-line option.
options = webdriver.ChromeOptions()
options.add_argument(r'--load- 
extension=C:\Users\lap0042\AppData\Local\Google\Chrome\User 
Data\Default\Extensions\omghfjlpggmjjaagoclmmobgdodcjboh')

# Initalize the driver with the appropriate options.
driver = webdriver.Chrome(chrome_options=options)

driver.get("http://stackoverflow.com")

This results in error "Failed to load extension from . Manifest files is missing or unreadable"

After search for this error I get that Manifest.json file should be renamed to manifest.json.txt but doing this resulted in same error.

Any help will be highly appreciated

enter image description here

Community
  • 1
  • 1
user3121891
  • 1,807
  • 3
  • 15
  • 13

5 Answers5

6

To open chrome browser with any extension you need to use the add_extension() method through an instance of chrome.options class and you can use the following solution :

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

chrome_options = Options()
chrome_options.add_extension(r'C:\path\to\extension.crx')
driver = webdriver.Chrome(chrome_options=chrome_options, executable_path=r'C:\Utility\BrowserDrivers\chromedriver.exe')
driver.get('https://www.google.co.in')
print("Page Title is : %s" %driver.title)
driver.quit()

References

You can find the relevant documentation in:

You can find a couple of relevant discussions in:

undetected Selenium
  • 183,867
  • 41
  • 278
  • 352
  • Thanks DebanjanB, this indeed add extension in the chrome but is disabled. is there any any that browser open with enabled extension? or what would be the best way to enable extension so that this may be used. – user3121891 May 21 '18 at 10:23
  • @user3121891 What exactly do you men by _but is disabled_, check the documentation I have added within my answer for your reference. – undetected Selenium May 21 '18 at 10:29
  • I mean extension is not activated. I want that when chromedriver is launched, it launches with extension already activated – user3121891 May 21 '18 at 10:40
1

if i understood correctly you're trying to load a local unpacked extension into selenium

in that case this code should work

options = options()
options.add_argument("--load-extension=" + unpackedExtensionPath)

a better option would be to pack your extension into a crx file

ahmed mani
  • 182
  • 1
  • 10
0

Use this code to fetch extensions

from selenium.webdriver.chrome.options import Options
from selenium.webdriver.common.desired_capabilities import DesiredCapabilities

ChromeOptions options = new ChromeOptions();
options.addExtensions(new File("/pathtoChromeextension.crx")); //adding 
DesiredCapabilities capabilities = new DesiredCapabilities();
capabilities.setCapability(ChromeOptions.CAPABILITY, options);
ChromeDriver driver = new ChromeDriver(capabilities);

Use below to get crx file http://crxextractor.com/ from your extension id which is omghfjlpggmjjaagoclmmobgdodcjboh

Moshe Slavin
  • 5,127
  • 5
  • 23
  • 38
Prany
  • 2,078
  • 2
  • 13
  • 31
  • Thanks Prany for your help. Im trying to find the CRX of Browsec or any good VPN plugin but no success yet. The app on the link http://crxextractor.com doesn't show any crx when i try to add file with extension id in it. In fact, there is no .CRX file in the folder of extension id. Can you help how i can find crx of any good VPN plugin – user3121891 May 21 '18 at 08:12
  • OK i extracted .crx file. Now can you please confirm if above code is for python 3? as it is showing error – user3121891 May 21 '18 at 08:18
  • @user3121891 - Have you added this at the top - 'from selenium.webdriver.chrome.options import Options' and 'from selenium.webdriver.common.desired_capabilities import DesiredCapabilities' – Prany May 21 '18 at 09:02
  • I think the script you shared is for java, Im looking for Pyhton – user3121891 May 21 '18 at 09:45
  • Prany. This is not correct syntax for python 3 as i get a lot of syntax errors on running this code – user3121891 May 22 '18 at 04:19
0

Simplest answer as far as I'm aware - manifest in subfolder of location you've referenced (e.g. 3.28.2_0' or whatever the latest version of extension is...)

This assumes you're using 'options.add_argument('--load-extension=')...

For options.add_extension('reference crx file .crx')

JB-007
  • 2,156
  • 1
  • 6
  • 22
  • possible duplicate of https://stackoverflow.com/a/66514495/13607672 – JB-007 Mar 07 '21 at 08:21
  • (In actuality, the correct answer is what I stated above - all this person needs to do is include the sub-folder name the extension path).... – JB-007 Mar 07 '21 at 08:22
-1

For Python you need wright path to manifest.json file

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

path = os.path.dirname(r"C:\temp\mdnleldcmiljblolnjhpnblkcekpdkpa\19.5.1.10_0\manifest.json")

options = Options()
options.add_argument(f"--load-extension={path}")
driver = webdriver.Chrome(options=options)