using DotNetBrowser;
using DotNetBrowser.WPF;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;

namespace NetworkDelegateSample
    class Program
        private class SampleNetworkDelegate : DefaultNetworkDelegate
            public override void OnBeforeURLRequest(BeforeURLRequestParams parameters) {
                // If navigate to teamdev.com, then change URL to google.com.
                if (parameters.Url == "http://www.teamdev.com/") {

            public override void OnBeforeSendHeaders(BeforeSendHeadersParams parameters) {
                // If navigate to google.com, then print User-Agent header value.
                if (parameters.Url == "http://www.google.com/") {
                    HttpHeaders headers = parameters.Headers;
                    Console.WriteLine("User-Agent: " + headers.GetHeader("User-Agent"));

        public class WindowMain : Window
            private WPFBrowserView browserView;

            public WindowMain()
                BrowserContext browserContext = BrowserContext.DefaultContext;
                browserContext.NetworkService.NetworkDelegate = new SampleNetworkDelegate();

                Browser browser = BrowserFactory.Create(browserContext);
                browserView = new WPFBrowserView(browser);

                Content = browserView;

                Width = 1024;
                Height = 768;
                this.Loaded += WindowMain_Loaded;

            void WindowMain_Loaded(object sender, RoutedEventArgs e)

            public static void Main()
                Application app = new Application();

                WindowMain wnd = new WindowMain();

                var browser = wnd.browserView.Browser;


Imports DotNetBrowser
Imports DotNetBrowser.WPF
Imports System.Windows

Module NetworkDelegateSample
    Private Class SampleNetworkDelegate
        Inherits DefaultNetworkDelegate

        Public Overrides Sub OnBeforeURLRequest(ByVal parameters As BeforeURLRequestParams)
            'If navigate to teamdev.com, then change URL to google.com.
            If parameters.Url = "http://www.teamdev.com/" Then
            End If
        End Sub

        Public Overrides Sub OnBeforeSendHeaders(ByVal parameters As BeforeSendHeadersParams)
            'If navigate to google.com, then print User-Agent header value.
            If parameters.Url = "http://www.google.com/" Then
                Dim headers As HttpHeaders = parameters.Headers
                Console.WriteLine("User-Agent: " & headers.GetHeader("User-Agent"))
            End If
        End Sub
    End Class

    Public Class WindowMain
        Inherits Window

        Private browserView As WPFBrowserView

        Public Sub New()
            Dim browserContext As BrowserContext = BrowserContext.DefaultContext
            browserContext.NetworkService.NetworkDelegate = New SampleNetworkDelegate()
            Dim browser As Browser = BrowserFactory.Create(browserContext)
            browserView = New WPFBrowserView(browser)
            Content = browserView
            Width = 1024
            Height = 768
            AddHandler Me.Loaded, AddressOf WindowMain_Loaded
        End Sub

        Private Sub WindowMain_Loaded(ByVal sender As Object, ByVal e As RoutedEventArgs)
        End Sub

        Public Shared Sub Main()
            Dim app As Application = New Application()
            Dim wnd As WindowMain = New WindowMain()
            Dim browser = wnd.browserView.Browser
        End Sub
    End Class
End Module