How can I launch Chrome with an unpacked extension?

前端 未结 7 990
孤街浪徒
孤街浪徒 2020-12-20 12:28

I\'m using Selenium WebDriver to test a Google Chrome extension I\'m developing. I noticed that ChromeDriver can be customised to add extensions to the instance

相关标签:
7条回答
  • 2020-12-20 12:51

    I was able to achieve this by using the AddArgument method to directly pass the information to Chrome. Here's what it looks like in C#:

    options = new ChromeOptions();
    options.AddArgument("--load-extension=" + unpackedExtensionPath);
    
    0 讨论(0)
  • 2020-12-20 12:54

    For packed extensions (a .crx file)

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

    For unpacked extensions (a local folder)

    ChromeOptions options = new ChromeOptions();
    options.addArguments("load-extension=/path/to/extension");
    DesiredCapabilities capabilities = new DesiredCapabilities();
    capabilities.setCapability(ChromeOptions.CAPABILITY, options);
    ChromeDriver driver = new ChromeDriver(capabilities);
    

    source

    0 讨论(0)
  • 2020-12-20 13:01

    It may be late but for future users:

    https://sites.google.com/a/chromium.org/chromedriver/extensions

    0 讨论(0)
  • 2020-12-20 13:04

    In Python3 it can be done like this:

    from selenium.webdriver import Chrome, ChromeOptions
    
    options = ChromeOptions()
    options.add_argument("load-extension=/path/to/unpacked_ext")
    
    driver = Chrome("/path/to/chromedriver", options=options)
    
    # (optional) Look at the uploaded extension
    driver.get("chrome://extensions")
    
    
    0 讨论(0)
  • 2020-12-20 13:09

    The unpacked extension error popped up for me and I requested for removing the restrictions in chrome which was enforced as organizational policy. Once the restrictions were removed, I am able to run the program with out any errors. ChromeBrowser-GPO-Deny - this was the one which was removed. You can check in Settings - Extensions - Check on Developer mode and see if the load unpacked extensions is checked once the restrictions are removed. You should be good then. All the above will work only when the chrome is not restricted.

    0 讨论(0)
  • 2020-12-20 13:12

    Here is apython example using webdriver_manager

    from selenium import webdriver
    from webdriver_manager.chrome import ChromeDriverManager
    
    
    options = webdriver.ChromeOptions()
    # loading the extension Edit-This-Cookie
    options.add_argument("--load-extension=./Edit-This-Cookie")
    driver = webdriver.Chrome(ChromeDriverManager().install(), chrome_options=options)
    
    driver.get("https://google.com")
    
    0 讨论(0)
提交回复
热议问题