DotNetBrowser

From Wikipedia, the free encyclopedia
Jump to navigation Jump to search
DotNetBrowser
DeveloperTeamDev
Initial release6 April 2015; 11 years ago (2015-04-06)
Repository
  • {{URL|example.com|optional display text}}Lua error in Module:EditAtWikidata at line 29: attempt to index field 'wikibase' (a nil value).
Written inC#, C++
Engine
    Lua error in Module:EditAtWikidata at line 29: attempt to index field 'wikibase' (a nil value).
    Operating systemMicrosoft Windows, Linux, macOS
    TypeFramework, Web browser
    LicenseProprietary[1]

    DotNetBrowser is a proprietary .NET library that provides a Chromium-based engine which can be used to load and display web pages.[2] [3][4] It is developed and supported by TeamDev since 2015.

    Features

    [edit | edit source]

    Some main features are as follows:

    • Load and display the web page.
    • Embed a Chromium-based browser in a .NET desktop application as an Avalonia UI, WPF or Windows Forms control.[5]
    • Handle navigation and network events.
    • Access Document Object Model of the loaded web page.
    • Execute JavaScript on the loaded web page, inject .NET objects and call them from JavaScript[6][7][8]

    Usage

    [edit | edit source]

    Primary usage is embedding a browser into various .NET desktop applications and displaying the web pages.[9] DotNetBrowser can be used as a headless browser. The headless mode is also available on Linux and macOS.

    Another known use-cases are creating web-based kiosk applications[10] and VSTO add-ins for Microsoft Office.[11]

    More examples and use-cases are available in the DotNetBrowser Examples repository.

    Example

    [edit | edit source]

    XAML markup

    <Window x:Class="Sample.Wpf.MainWindow"
            xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
            xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
            xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
            xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
            xmlns:wpf="clr-namespace:DotNetBrowser.Wpf;assembly=DotNetBrowser.Wpf"
            mc:Ignorable="d"
            Title="MainWindow" Height="450" Width="800" Closed="MainWindow_OnClosed">
        <Grid>
            <wpf:BrowserView x:Name="browserView"/>
        </Grid>
    </Window>
    

    C#

    using System;
    using System.Windows
    using DotNetBrowser.Browser;
    using DotNetBrowser.Engine;
    
    namespace Sample.Wpf;
    
    public partial class MainWindow : Window
    {
        private readonly IEngine _engine;
        private readonly IBrowser _browser;
         
        public MainWindow()
        {
            InitializeComponent();
             
            // Create and initialize the IEngine
            _engine = EngineFactory.Create();
             
            // Create the IBrowser
            _browser = engine.CreateBrowser();
            _browser.Navigation.LoadUrl("https://teamdev.com/dotnetbrowser");
             
            // Initialize the WPF BrowserView control
            browserView.InitializeFrom(browser);
        }
         
        private void MainWindow_OnClosed(object sender, EventArgs e)
        {
            _browser.Dispose();
            _engine.Dispose();
        }
    }
    

    Windows Forms

    [edit | edit source]

    C#

    using System;
    using System.Windows.Forms;
    using DotNetBrowser.Browser;
    using DotNetBrowser.Engine;
    using DotNetBrowser.WinForms;
    
    namespace Sample.WinForms;
    
    public partial class Form1 : Form
    {
        private readonly IEngine _engine;
        private readonly IBrowser _browser;
         
        public Form1()
        {
            InitializeComponent();
             
            // Create and initialize the IEngine
            _engine = EngineFactory.Create();
             
            // Create the Windows Forms BrowserView control
            var browserView = new BrowserView
            {
                Dock = DockStyle.Fill
            };
             
            // Create the IBrowser
            _browser = engine.CreateBrowser();
            _browser.Navigation.LoadUrl("https://teamdev.com/dotnetbrowser");
             
            // Initialize the Windows Forms BrowserView control
            browserView.InitializeFrom(browser);
             
            // Add the BrowserView control to the Form
            Controls.Add(browserView);
            Closed += Form1Closed;
        }
         
        private void Form1Closed(object sender, EventArgs e)
        {
            _browser.Dispose();
            _engine.Dispose();
        }
    }
    

    See also

    [edit | edit source]

    References

    [edit | edit source]
    1. ^ Lua error in Module:Citation/CS1/Configuration at line 2172: attempt to index field '?' (a nil value).
    2. ^ Lua error in Module:Citation/CS1/Configuration at line 2172: attempt to index field '?' (a nil value).
    3. ^ Lua error in Module:Citation/CS1/Configuration at line 2172: attempt to index field '?' (a nil value).
    4. ^ Lua error in Module:Citation/CS1/Configuration at line 2172: attempt to index field '?' (a nil value).
    5. ^ Lua error in Module:Citation/CS1/Configuration at line 2172: attempt to index field '?' (a nil value).
    6. ^ Lua error in Module:Citation/CS1/Configuration at line 2172: attempt to index field '?' (a nil value).
    7. ^ Lua error in Module:Citation/CS1/Configuration at line 2172: attempt to index field '?' (a nil value).
    8. ^ Lua error in Module:Citation/CS1/Configuration at line 2172: attempt to index field '?' (a nil value).
    9. ^ Lua error in Module:Citation/CS1/Configuration at line 2172: attempt to index field '?' (a nil value).
    10. ^ Lua error in Module:Citation/CS1/Configuration at line 2172: attempt to index field '?' (a nil value).
    11. ^ Lua error in Module:Citation/CS1/Configuration at line 2172: attempt to index field '?' (a nil value).
    [edit | edit source]
    • Official website
    • Lua error in Module:Citation/CS1/Configuration at line 2172: attempt to index field '?' (a nil value). - the DotNetBrowser support website containing documentation and release notes.
    • Lua error in Module:Citation/CS1/Configuration at line 2172: attempt to index field '?' (a nil value). - the repository containing various examples of using DotNetBrowser.