internal async Task <CoverageEntry[]> StopAsync() { if (!_enabled) { throw new InvalidOperationException("CSSCoverage is not enabled"); } _enabled = false; var trackingResponse = await _client.SendAsync(new CSSStopRuleUsageTrackingRequest()).ConfigureAwait(false); await Task.WhenAll( _client.SendAsync(new CSSDisableRequest()), _client.SendAsync(new DOMDisableRequest())).ConfigureAwait(false); _client.MessageReceived -= Client_MessageReceived; var styleSheetIdToCoverage = new Dictionary <string, List <CoverageRange> >(); foreach (var entry in trackingResponse.RuleUsage) { styleSheetIdToCoverage.TryGetValue(entry.StyleSheetId, out var ranges); if (ranges == null) { ranges = new List <CoverageRange>(); styleSheetIdToCoverage[entry.StyleSheetId] = ranges; } ranges.Add(new CoverageRange { StartOffset = (int?)entry.StartOffset.Value, EndOffset = (int?)entry.EndOffset.Value, Count = entry.Used == true ? 1 : 0, }); } var coverage = new List <CoverageEntry>(); foreach (string styleSheetId in _stylesheetURLs.Keys) { string url = _stylesheetURLs[styleSheetId]; string text = _stylesheetSources[styleSheetId]; styleSheetIdToCoverage.TryGetValue(styleSheetId, out var responseRanges); var ranges = Coverage.ConvertToDisjointRanges(responseRanges ?? new List <CoverageRange>()); coverage.Add(new CoverageEntry { Url = url, Ranges = ranges, Text = text, }); } return(coverage.ToArray()); }
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()); }