Skip to content
Snippets Groups Projects
Program.cs 2.45 KiB
Newer Older
  • Learn to ignore specific revisions
  • using MasterDevs.ChromeDevTools.Protocol.Chrome.Page;
    
    namespace MasterDevs.ChromeDevTools.Sample
    
    brewdente's avatar
    brewdente committed
        internal class Program
    
    brewdente's avatar
    brewdente committed
            private static void Main(string[] args)
    
                    // STEP 1 - Run Chrome
                    var chromeProcessFactory = new ChromeProcessFactory();
                    using (var chromeProcess = chromeProcessFactory.Create(9222))
                    {
                        // STEP 2 - Create a debugging session
    
    Georgios Diamantopoulos's avatar
    Georgios Diamantopoulos committed
                        var sessionInfo = (await chromeProcess.GetSessionInfo()).LastOrDefault();
    
    Georgios Diamantopoulos's avatar
    Georgios Diamantopoulos committed
                        var chromeSession = chromeSessionFactory.Create(sessionInfo.WebSocketDebuggerUrl);
    
                        // STEP 3 - Send a command
                        //
                        // Here we are sending a command to tell chrome to navigate to
                        // the specified URL
                        var navigateResponse = chromeSession.SendAsync(new NavigateCommand
    
                        {
                            Url = "http://www.google.com"
                        })
    
                            .Result;
                        Console.WriteLine("NavigateResponse: " + navigateResponse.Id);
    
                        // STEP 4 - Register for events (in this case, "Page" domain events)
                        // send an event to tell chrome to send us all Page events
                        // but we only subscribe to certain events in this session
                        var pageEnableResult = chromeSession.SendAsync<ChromeDevTools.Protocol.Chrome.Page.EnableCommand>().Result;
                        Console.WriteLine("PageEnable: " + pageEnableResult.Id);
                        chromeSession.Subscribe<Protocol.Chrome.Page.DomContentEventFiredEvent>(domContentEvent =>
    
                            Console.WriteLine("DomContentEvent: " + domContentEvent.Timestamp);
    
                        // you might never see this, but that's what an event is ... right?
                        chromeSession.Subscribe<Protocol.Chrome.Page.FrameStartedLoadingEvent>(frameStartedLoadingEvent =>
    
                            Console.WriteLine("FrameStartedLoading: " + frameStartedLoadingEvent.FrameId);
    
    brewdente's avatar
    brewdente committed
    }