2

How can I load a chrome extension to PuppeteerSharp's driver, similar to Selenium's option:

ChromeOptions options = new ChromeOptions();
options.AddExtension(@"C:\a\path\to\file.zip");
Shai Ben-Dor
  • 533
  • 9
  • 21

2 Answers2

2

Based on Line 43 of the LanchOptions.cs you can specify arguments to the launch process.

Now connecting this with the native JavaScript (using the --load-extension flag) the output should look similar to the following:

var browser = await Puppeteer.LaunchAsync(new LaunchOptions
{
    Args = new string[1] { "--load-extension=/Path/To/Extension/Folder" }
});

Note: that I put path to folder, not the .zip as you have in your sample.. if you want to load multiple extensions then just separate the paths using a comma.

Here's a full list of possible arguments that can be passed in to Chromium.

Adrian
  • 8,271
  • 2
  • 26
  • 43
1

According to this issie, next piece of code works for me:

var browser = await Puppeteer.LaunchAsync(new LaunchOptions
{
    Args = new string[1] 
    {
       "--disable-extensions-except=${pathToExtension}",
       "--load-extension=${pathToExtension}"
    }
});

Sometimes it can't load some extensions when they are packed (*.crx or *.zip files). Then unpacking this extensions can help.

Community
  • 1
  • 1
DanilaNV
  • 169
  • 2
  • 4
  • 13