/// <summary> /// Asynchronously starts the session. /// </summary> /// <param name="protocolVersion">The version of the protocol to use in communicating with the browswer.</param> /// <returns>A task that represents the asynchronous operation.</returns> internal async Task Start(int protocolVersion) { string debuggerUrl = string.Format(CultureInfo.InvariantCulture, "http://{0}", this.debuggerEndpoint); string rawVersionInfo = string.Empty; using (HttpClient client = new HttpClient()) { client.BaseAddress = new Uri(debuggerUrl); rawVersionInfo = await client.GetStringAsync("/json/version"); } var versionInfo = JsonConvert.DeserializeObject <DevToolsVersionInfo>(rawVersionInfo); websocketAddress = versionInfo.WebSocketDebuggerUrl; if (protocolVersion == AutoDetectDevToolsProtocolVersion) { bool versionParsed = int.TryParse(versionInfo.BrowserMajorVersion, out protocolVersion); if (!versionParsed) { throw new WebDriverException(string.Format(CultureInfo.InvariantCulture, "Unable to parse version number received from browser. Reported browser version string is '{0}'", versionInfo.Browser)); } } this.domains = DevToolsDomains.InitializeDomains(protocolVersion, this); string targetId = null; var targets = await this.domains.Target.GetTargets(); foreach (var target in targets) { if (target.Type == "page") { targetId = target.TargetId; LogTrace("Found Target ID {0}.", targetId); string sessionId = await this.domains.Target.AttachToTarget(targetId); LogTrace("Target ID {0} attached. Active session ID: {1}", targetId, sessionId); this.ActiveSessionId = sessionId; break; } } await this.domains.Target.SetAutoAttach(); LogTrace("AutoAttach is set.", targetId); try { // Wrap this in a try-catch, because it's not the end of the // world if clearing the log doesn't work. await this.domains.Log.Clear(); LogTrace("Log cleared.", targetId); } catch (WebDriverException) { } }
/// <summary> /// Asynchronously starts the session. /// </summary> /// <returns>A task that represents the asynchronous operation.</returns> public async Task Start() { string debuggerUrl = string.Format(CultureInfo.InvariantCulture, "http://{0}", this.debuggerEndpoint); string rawVersionInfo = string.Empty; using (HttpClient client = new HttpClient()) { client.BaseAddress = new Uri(debuggerUrl); rawVersionInfo = await client.GetStringAsync("/json/version"); } var versionInfo = JsonConvert.DeserializeObject <DevToolsVersionInfo>(rawVersionInfo); websocketAddress = versionInfo.WebSocketDebuggerUrl; this.domains = DevToolsDomains.InitializeDomains(versionInfo, this); string targetId = null; var targets = await this.domains.Target.GetTargets(); foreach (var target in targets) { if (target.Type == "page") { targetId = target.TargetId; LogTrace("Found Target ID {0}.", targetId); string sessionId = await this.domains.Target.AttachToTarget(targetId); LogTrace("Target ID {0} attached. Active session ID: {1}", targetId, sessionId); this.ActiveSessionId = sessionId; break; } } await this.domains.Target.SetAutoAttach(); LogTrace("AutoAttach is set.", targetId); await this.domains.Log.Clear(); LogTrace("Log cleared.", targetId); }
/// <summary> /// Asynchronously starts the session. /// </summary> /// <param name="requestedProtocolVersion">The requested version of the protocol to use in communicating with the browswer.</param> /// <returns>A task that represents the asynchronous operation.</returns> internal async Task StartSession(int requestedProtocolVersion) { int protocolVersion = await InitializeProtocol(requestedProtocolVersion); this.domains = DevToolsDomains.InitializeDomains(protocolVersion, this); await this.InitializeSocketConnection(); await this.InitializeSession(); try { // Wrap this in a try-catch, because it's not the end of the // world if clearing the log doesn't work. await this.domains.Log.Clear(); LogTrace("Log cleared.", this.attachedTargetId); } catch (WebDriverException) { } }