/// <inheritdoc cref="IBrowser.StopTracingAsync"/>
        public async Task <string> StopTracingAsync()
        {
            var taskWrapper = new TaskCompletionSource <string>(TaskCreationOptions.RunContinuationsAsynchronously);

            async void EventHandler(object sender, IChromiumEvent e)
            {
                try
                {
                    if (e is TracingTracingCompleteChromiumEvent tracingTracingComplete)
                    {
                        string stream      = tracingTracingComplete.Stream;
                        string tracingData = await ProtocolStreamReader.ReadProtocolStreamStringAsync(_tracingClient, stream, _tracingPath).ConfigureAwait(false);

                        _client.MessageReceived -= EventHandler;
                        taskWrapper.TrySetResult(tracingData);
                    }
                }
                catch (Exception ex)
                {
                    string message = $"Tracing failed to process the tracing complete. {ex.Message}. {ex.StackTrace}";
                    System.Diagnostics.Debug.WriteLine(ex);
                    _tracingClient.OnClosed(message);
                }
            }

            _tracingClient.MessageReceived += EventHandler;

            await _tracingClient.SendAsync(new TracingEndRequest()).ConfigureAwait(false);

            _tracingRecording = false;

            return(await taskWrapper.Task.ConfigureAwait(false));
        }
        public async Task <byte[]> GenerateAsync(string file, PdfOptions options)
        {
            double paperWidth  = PaperFormat.Letter.Width;
            double paperHeight = PaperFormat.Letter.Height;

            if (options.Format != null)
            {
                paperWidth  = options.Format.Width;
                paperHeight = options.Format.Height;
            }
            else
            {
                if (options.Width != null)
                {
                    paperWidth = ConvertPrintParameterToInches(options.Width);
                }

                if (options.Height != null)
                {
                    paperHeight = ConvertPrintParameterToInches(options.Height);
                }
            }

            double marginTop    = ConvertPrintParameterToInches(options.MarginOptions.Top);
            double marginLeft   = ConvertPrintParameterToInches(options.MarginOptions.Left);
            double marginBottom = ConvertPrintParameterToInches(options.MarginOptions.Bottom);
            double marginRight  = ConvertPrintParameterToInches(options.MarginOptions.Right);

            var result = await _client.SendAsync(new PagePrintToPDFRequest
            {
                TransferMode        = "ReturnAsStream",
                Landscape           = options.Landscape,
                DisplayHeaderFooter = options.DisplayHeaderFooter,
                HeaderTemplate      = options.HeaderTemplate,
                FooterTemplate      = options.FooterTemplate,
                PrintBackground     = options.PrintBackground,
                Scale             = options.Scale,
                PaperWidth        = paperWidth,
                PaperHeight       = paperHeight,
                MarginTop         = marginTop,
                MarginBottom      = marginBottom,
                MarginLeft        = marginLeft,
                MarginRight       = marginRight,
                PageRanges        = options.PageRanges,
                PreferCSSPageSize = options.PreferCSSPageSize,
            }).ConfigureAwait(false);

            return(await ProtocolStreamReader.ReadProtocolStreamByteAsync(_client, result.Stream, file).ConfigureAwait(false));
        }