We’re happy to announce that Chrome extensions in DotNetBrowser are in public preview!

This article give a quick overview on how to install and use extensions in DotNetBrowser.

uBlock extension in DotNetBrowser

An extension launched in DotNetBrowser

Chrome extensions in a web view bring new capabilities into your software at no cost. With extensions, you can block ads, improve accessibility, use developer tools of JavaScript libraries, and many more.

Clone the demo application 

Here’s how to get the demo application:

  1. Clone DotNetBrowser-Examples repository.

    git clone https://github.com/TeamDev-IP/DotNetBrowser-Examples.git
    
  2. Switch to the extensions-preview branch:

    git checkout 3.x.x
    
  3. Get a free 30-day trial license. Fill out the form, and you will receive an email with the license key immediately.

Spinner

Sending…

Sorry, the sending was interrupted

Please try again. If the issue persists, contact us at info@teamdev.com.

Read and agree to the terms to continue.

Your personal DotNetBrowser trial key and quick start guide will arrive in your Email Inbox in a few minutes.

  1. Put your license key into the dotnetbrowser.license file in the root of the repository.
  2. Open the solution in Visual Studio 2019 or newer.
  3. Right-click the solution in “Solution Explorer” and select “Restore NuGet Packages.”
  4. Build the solution and run the Extensions project.

Use in the existing project 

If you already use DotNetBrowser, you can get the preview build from NuGet:

dotnet add package DotNetBrowser -v "v3.0.0-eap.2"
dotnet add package DotNetBrowser.WPF -v "v3.0.0-eap.2"

Install the extension 

Installing an extension is straightforward:

// The path to the extension file.
string crx = Path.GetFullPath("path/to/extension.crx");

// Install the extension and wait until installed.
var extensions = engine.Profiles.Default.Extensions;
IExtension extension = await extensions.Install(crx);

Interact with extension 

Every extension has an icon in the Chrome toolbar. When a user clicks on the icon, the extension usually does something. For example, it may show a small pop-up or silently change the content of the page.

In DotNetBrowser, there isn’t a toolbar or icon to click on. So instead, we provide the API to “click on the icon” from code:

extension.GetAction(browser)?.Click();

If the extension wants to show a pop-up, DotNetBrowser will open it as a new window. But you can change this behavior.

The extension’s pop-up is a regular IBrowser instance. So you can do anything: show it inside the existing window, make it transparent, or turn it into a modal dialog. In fact, you may decide not to show it at all.

In this example, we don’t display the pop-up and do some automation instead:

using DotNetBrowser.Browser.Handlers;
...
Browser.OpenExtensionActionPopupHandler = 
    new Handler<OpenExtensionActionPopupParameters>(p =>
    {
        IBrowser popupBrowser = p.PopupBrowser;
        // As soon as the frame is loaded, automate necessary actions.
        PopupBrowser.Navigation.FrameLoadFinished += (s, e) =>
        {
            if (e.Frame.IsMain)
            {
                // Click on the button switch button.
                e.Frame.GetElementById("switch").Click();
            }
        };
    });

Give us extensions to check 

Integrating Chrome extensions into DotNetBrowser marks a significant step forward, offering more possibilities for enhancing .NET applications. With this update, we invite developers to explore and provide feedback.

your thoughts and which extensions you want to use.