private async Task <ChromeProcessInfo> OpenChromeProfile(string userDir) { ChromeProcessInfo res = null; await Task.Run(() => res = ChromeProfilesWorker.OpenChromeProfile(userDir, Port)); return(res); }
public async Task <string> Close(CancellationToken cancellationToken = default(CancellationToken)) { if (isConnected) { await Disconnect(); } if (chromeProcess?.Proc != null && !chromeProcess.Proc.HasExited) { try { chromeProcess.Proc.CloseMainWindow(); } catch { try { chromeProcess.Proc.Kill(); } catch { } } while (!chromeProcess.Proc.HasExited) { await Task.Delay(250); } } chromeProcess?.Proc?.Dispose(); if (chromeProcess?.ProcWithJobObject != null) { chromeProcess.ProcWithJobObject.TerminateProc(); } chromeProcess = null; await Task.Delay(1000); if (IsTempUserDir) { try { if (Directory.Exists(UserDir)) { Directory.Delete(UserDir, true); } } catch { Thread.Sleep(3000); try { if (Directory.Exists(UserDir)) { Directory.Delete(UserDir, true); } } catch { } } } return("ok"); }
public virtual async Task <string> Connect(CancellationToken cancellationToken = default(CancellationToken)) { UnsubscribeDevToolsSessionEvent(); DoConnectWhenCheckConnected = false; if (!string.IsNullOrWhiteSpace(UserDir)) { chromeProcess = await OpenChromeProfile(UserDir); } await DevTools.Connect(); SubscribeToDevToolsSessionEvent(); await FrameTracker.Enable(); return($"Connected to Chrome port {Port}"); }