Skip to content

Conversation

@Daddoon
Copy link
Contributor

@Daddoon Daddoon commented Sep 26, 2019

This PR add the support of:

  • BrowserWindow.AddExtension
  • BrowserWindow.RemoveExtension
  • BrowserWindow.GetExtensions

I have tested the code on my side by loading the updated ElectronNET.CLI, and tested with the following sample test in Startup.cs:

        public async void ElectronBootstrap()
        {
            var browserWindow = await Electron.WindowManager.CreateWindowAsync(new BrowserWindowOptions
            {
                Width = 1152,
                Height = 940,
                Show = false
            });

            await browserWindow.WebContents.Session.ClearCacheAsync();

            browserWindow.OnReadyToShow += async () =>
            {
                browserWindow.Show();

                await Electron.Dialog.ShowMessageBoxAsync(browserWindow, $"Chrome Extensions test");

                //Test for webextensions
                string extensionName = await BrowserWindow.AddExtensionAsync(@"C:/2Bee/Sources/ElectronNET/Electron.NET/ElectronNET.WebApp/wwwroot/chromextensions/iframe_listener");
                await Electron.Dialog.ShowMessageBoxAsync(browserWindow, $"AddExtension: Loaded extension is {extensionName}");

                var extensionsList = await BrowserWindow.GetExtensionsAsync();
                var extensionListString = string.Join(", ", extensionsList.Select(p => $"Name: {p.Name}, Version: {p.Version}"));

                await Electron.Dialog.ShowMessageBoxAsync(browserWindow, $"GetExtensionsAsync: Results are: {extensionListString}");

                BrowserWindow.RemoveExtension(extensionName);

                var extensionsListAfterRemove = await BrowserWindow.GetExtensionsAsync();
                var extensionListAfterRemoveString = string.Join(", ", extensionsListAfterRemove.Select(p => $"Name: {p.Name}, Version: {p.Version}"));

                await Electron.Dialog.ShowMessageBoxAsync(browserWindow, $"GetExtensionsAsync after remove extension: Results are: {extensionListAfterRemoveString}");
            };
            browserWindow.SetTitle(Configuration["DemoTitleInSettings"]);
        }

Attached here, a little Chrome extension created from a Mozilla WebExtension i created for my plugin BlazorMobile. Actually, the running code in this extension should not work as it's specific for a special expected environment, but the goal here is just to test that the Chrome extension load in Electron.

chromextensions.zip

Of course update the AddExtensionAsync with a valid extension folder on your side.
The shown dialog should validate the expected behaviors, according to the method call orders and expected return values.

- Added a ChromeExtensionInfo class, that mimic the returned JS values from GetExtensions method (see https://electronjs.org/docs/api/browser-window#browserwindowgetextensions)
- GetExtensions return a Dictionary<string, ChromeExtensionInfo>, to respect JS documentation declaration.
- Sample for quick testing will be put in the pull request
@Daddoon
Copy link
Contributor Author

Daddoon commented Sep 27, 2019

Just asking a question, do you have any clues about the release pace from your project ?

I mean, i require theses functionnalities for some plugin implementation on my project BlazorMobile for the Desktop side (using ElectronNET), as this way i would be able to mimic with nearly the exact same code base the code i have done in GeckoView for Android using WebExtensions instead, for managing cleanly some DOM events, like Navigating event from main window, and nested Navigating events from iFrame and subiframes from a same window.

I'm actually trying to implement a kind of minimalist Xamarin.Forms driver for ElectronNET, though this is not the goal, it's just for managing the same code call base from a Xamarin.Forms project, as used on the native side of my plugin.

The binding of Chrome extensions here is mainly to enforce on my side to easily catch / block DOM navigating events, and reforwarding them on a WebView Navigating event like a Xamarin.Forms project, to enforce continuation or to cancel depending the developer choice.

I would prefer to continue to use the ElectronNET main repo instead of forking on my own dependencies on my project for having this functionnality.

I may workaround temporiraly by calling remotes IPC from the web page, but it would be a lot more difficult, as it would be the Web application responsible of managing the required information / path etc, instead of the "native" side in C# of the app.

Thanks in advance for any feedback :) !

@GregorBiswanger GregorBiswanger added this to the 7.30.2 milestone Nov 27, 2019
@GregorBiswanger GregorBiswanger self-assigned this Nov 27, 2019
@GregorBiswanger GregorBiswanger merged commit 4e8e771 into ElectronNET:master Nov 27, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants