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

namespace GetFrameIDsSample
    class Program
        public class WindowMain : Window
            private WPFBrowserView browserView;

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

                Content = browserView;

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

                browser.FinishLoadingFrameEvent += delegate(object sender, FinishLoadingEventArgs e)
                    if (e.IsMainFrame)
                        // Get HTML of each frame on the web page
                        PrintFrameHierarhy(browser, BrowserFrameID.MAIN_FRAME_ID);

            void WindowMain_Loaded(object sender, RoutedEventArgs e)

            public static void PrintFrameHierarhy(Browser browser, long frameId)
                var framesIds = browser.GetFramesIds(frameId);
                foreach (var id in framesIds)
                    String html = browser.GetHTML(id);
                    Console.WriteLine(id + " HTML = " + html);
                    PrintFrameHierarhy(browser, id);

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

                WindowMain wnd = new WindowMain();

                var browser = wnd.browserView.Browser;


Imports DotNetBrowser
Imports DotNetBrowser.Events
Imports DotNetBrowser.WPF
Imports System.Windows

Module GetFrameIDsSample
    Public Class WindowMain
        Inherits Window

        Private browserView As WPFBrowserView

        Public Sub New()
            Dim browser As Browser = BrowserFactory.Create()
            browserView = New WPFBrowserView(browser)
            Content = browserView
            Width = 1024
            Height = 768
            AddHandler Me.Loaded, AddressOf WindowMain_Loaded
            AddHandler browser.FinishLoadingFrameEvent, sub(ByVal sender As Object, ByVal e As FinishLoadingEventArgs)

                If e.IsMainFrame Then
                    'Get HTML of each frame on the web page
                    PrintFrameHierarhy(browser, BrowserFrameID.MAIN_FRAME_ID)
                End If
            End sub
        End Sub

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

        Public Shared Sub PrintFrameHierarhy(ByVal browser As Browser, ByVal frameId As Long)
            Dim framesIds = browser.GetFramesIds(frameId)

            For Each id In framesIds
                Dim html As String = browser.GetHTML(id)
                Console.WriteLine(id & " HTML = " & html)
                PrintFrameHierarhy(browser, id)
        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