Search code examples
c#winformsbrowserwebview2

Extensions on WebView2 on WinForms


I would like to use AdBlock extension in WebView2. How can i add extensions to WebView2?

I have searched and found out that WebView currently doesnt support extensions. If there is some play around then let me know please.


Solution

  • (Updated 2024-09-12 to note that WebView2 now supports browser extensions)

    WebView2 now supports browser extensions. If you have a CoreWebView2 instance, you can do the following to add an extension:

    coreWebView2.Profile.AddBrowserExtensionAsync(pathToExtensionFolder);
    

    In the above pathToExtensionFolder must be a folder that contains the source for an extension including the manifest.json file for that extension. You cannot use the method to directly install an extension from any kind of online store nor from a packaged extension file.

    Once added you can enumerate installed extensions using the coreWebView2.Profile.GetBrowserExtensionsAsync() method. The extension is installed to the CoreWebView2's user data folder and will persist across WebView2 sessions until you remove it with browserExtension.RemoveAsync().