} // End Function InternalConnect

        private static async System.Threading.Tasks.Task <ConnectionInfo> ConnectToChrome(string chromePath, string remoteDebuggingUri)
        {
            ConnectionInfo ci = new ConnectionInfo();

            try
            {
                await InternalConnect(ci, remoteDebuggingUri);
            }
            catch (System.Exception ex)
            {
                if (ex.InnerException != null && object.ReferenceEquals(ex.InnerException.GetType(), typeof(System.Net.WebException)))
                {
                    if (((System.Net.WebException)ex.InnerException).Status == System.Net.WebExceptionStatus.ConnectFailure)
                    {
                        MasterDevs.ChromeDevTools.IChromeProcessFactory chromeProcessFactory =
                            new MasterDevs.ChromeDevTools.ChromeProcessFactory(new FastStubbornDirectoryCleaner(), chromePath);

                        // Create a durable process
                        // MasterDevs.ChromeDevTools.IChromeProcess persistentChromeProcess = chromeProcessFactory.Create(9222, false);
                        MasterDevs.ChromeDevTools.IChromeProcess persistentChromeProcess = chromeProcessFactory.Create(9222, true);

                        await InternalConnect(ci, remoteDebuggingUri);

                        return(ci);
                    } // End if (((System.Net.WebException)ex.InnerException).Status == System.Net.WebExceptionStatus.ConnectFailure)
                }     // End if (ex.InnerException != null && object.ReferenceEquals(ex.InnerException.GetType(), typeof(System.Net.WebException)))

                System.Console.WriteLine(chromePath);
                System.Console.WriteLine(ex.Message);
                System.Console.WriteLine(ex.StackTrace);

                if (ex.InnerException != null)
                {
                    System.Console.WriteLine(ex.InnerException.Message);
                    System.Console.WriteLine(ex.InnerException.StackTrace);
                } // End if (ex.InnerException != null)

                System.Console.WriteLine(ex.GetType().FullName);

                throw;
            } // End Catch

            return(ci);
        } // End Function ConnectToChrome
Пример #2
0
        private static async void StartNew()
        {
            KillHeadless();

            // STEP 1 - Run Chrome
            MasterDevs.ChromeDevTools.IChromeProcessFactory chromeProcessFactory =
                new MasterDevs.ChromeDevTools.ChromeProcessFactory(new StubbornDirectoryCleaner());

            //using (MasterDevs.ChromeDevTools.IChromeProcess chromeProcess = chromeProcessFactory.Create(9222, true))
            using (MasterDevs.ChromeDevTools.IChromeProcess chromeProcess = chromeProcessFactory.Create(9222, false))
            {
                // STEP 2 - Create a debugging session
                MasterDevs.ChromeDevTools.ChromeSessionInfo[] sessionInfos = await chromeProcess.GetSessionInfo();

                MasterDevs.ChromeDevTools.ChromeSessionInfo sessionInfo = (sessionInfos != null && sessionInfos.Length > 0) ?
                                                                          sessionInfos[sessionInfos.Length - 1]
                    : new MasterDevs.ChromeDevTools.ChromeSessionInfo();

                MasterDevs.ChromeDevTools.IChromeSessionFactory chromeSessionFactory = new MasterDevs.ChromeDevTools.ChromeSessionFactory();

                MasterDevs.ChromeDevTools.IChromeSession chromeSession = chromeSessionFactory.Create(sessionInfo.WebSocketDebuggerUrl);
            } // End Using chromeProcess
        }