internal async Task <CoverageEntry[]> StopAsync() { if (!_enabled) { throw new InvalidOperationException("JSCoverage is not enabled"); } _enabled = false; var profileResponseTask = _client.SendAsync <ProfilerTakePreciseCoverageResponse>(new ProfilerTakePreciseCoverageRequest()); await Task.WhenAll( profileResponseTask, _client.SendAsync(new ProfilerStopPreciseCoverageRequest()), _client.SendAsync(new ProfilerDisableRequest()), _client.SendAsync(new DebuggerDisableRequest())).ConfigureAwait(false); _client.MessageReceived -= Client_MessageReceived; var coverage = new List <CoverageEntry>(); foreach (var entry in profileResponseTask.Result.Result) { _scriptURLs.TryGetValue(entry.ScriptId, out string url); if (string.IsNullOrEmpty(url) && _reportAnonymousScripts) { url = "debugger://VM" + entry.ScriptId; } if (string.IsNullOrEmpty(url) || !_scriptSources.TryGetValue(entry.ScriptId, out string text)) { continue; } var flattenRanges = entry.Functions.SelectMany(f => f.Ranges).ToList(); var ranges = Coverage.ConvertToDisjointRanges(flattenRanges); coverage.Add(new CoverageEntry { Url = url, Ranges = ranges, Text = text, }); } return(coverage.ToArray()); }