How can I launch Chrome with an unpacked extension?

11,734

Solution 1

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);

Solution 2

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

Solution 3

It may be late but for future users:

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

Solution 4

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.

Share:
11,734

Related videos on Youtube

Sam
Author by

Sam

Updated on September 14, 2022

Comments

  • Sam
    Sam over 1 year

    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 of Chrome that it launches. This can be achieved using the AddExtension and AddExtensions methods of the ChromeOptions class.

    The documentation for these methods indicates that they require extensions to be provided as crx files. Since I'm developing the extension, I don't have a crx file. I would like to be able to load the unpacked extension, but I couldn't find a method to do this.

    I tried putting the extension files in a zip file and specifying this for the AddExtension method, but this caused an exception to occur since it wasn't a crx file. I also tried passing in the directory containing the unpacked files, but this produced a FileNotFoundException.

    How can I do this?

    • Yinda Yin
      Yinda Yin
      I have no idea what all of this means, but I upvoted your answer, because it does indeed seem like useful information.
  • Sam
    Sam over 9 years
    addExtensions seems to require a crx file, which represents a packed extension rather than an unpacked one.
  • Vladimir
    Vladimir over 6 years
    Second option would work only for local Selenium as /path/to/extension would not be available remotely.
  • Sriram Sridharan
    Sriram Sridharan over 5 years
    Can the same be done for the RemoteWebDriver, provided I have the unpacked extension on the client machine?
  • Hamza Idrees
    Hamza Idrees over 4 years
    My unpacked extension works when i load it manually, but when it is loaded by this method, there is an error saying "manifest file is missing or unreadable"
  • rednoyz
    rednoyz over 4 years
    are you specifying the correct local path in the second line?