Example #1
0
        internal async void OnMessageReceived(object sender, MessageEventArgs e)
        {
            try
            {
                switch (e.MessageID)
                {
                case "Runtime.executionContextCreated":
                    OnExecutionContextCreated(e.MessageData.ToObject <RuntimeExecutionContextCreatedResponse>(true));
                    break;

                case "Runtime.consoleAPICalled":
                    await OnConsoleAPICalled(e).ConfigureAwait(false);

                    break;

                case "Runtime.exceptionThrown":
                    OnExceptionThrown(e.MessageData.ToObject <RuntimeExceptionThrownResponse>(true));
                    break;
                }
            }
            catch (Exception ex)
            {
                var message = $"Worker failed to process {e.MessageID}. {ex.Message}. {ex.StackTrace}";
                //_logger.LogError(ex, message);
                _client.Close(message);
            }
        }
Example #2
0
        /// <summary>
        /// Stops tracing
        /// </summary>
        /// <returns>Stop task</returns>
        public async Task <string> StopAsync()
        {
            var taskWrapper = new TaskCompletionSource <string>(TaskCreationOptions.RunContinuationsAsynchronously);

            async void EventHandler(object sender, MessageEventArgs e)
            {
                try
                {
                    if (e.MessageID == "Tracing.tracingComplete")
                    {
                        var stream      = e.MessageData.ToObject <TracingCompleteResponse>().Stream;
                        var tracingData = await ProtocolStreamReader.ReadProtocolStreamStringAsync(_client, stream, _path).ConfigureAwait(false);

                        _client.MessageReceived -= EventHandler;
                        taskWrapper.TrySetResult(tracingData);
                    }
                }
                catch (Exception ex)
                {
                    var message = $"Tracing failed to process the tracing complete. {ex.Message}. {ex.StackTrace}";
                    _logger.LogError(ex, message);
                    _client.Close(message);
                }
            }

            _client.MessageReceived += EventHandler;

            await _client.SendAsync("Tracing.end").ConfigureAwait(false);

            _recording = false;

            return(await taskWrapper.Task.ConfigureAwait(false));
        }
Example #3
0
        /// <summary>
        /// Stops tracing
        /// </summary>
        /// <returns>Stop task</returns>
        public async Task <string> StopAsync()
        {
            var taskWrapper = new TaskCompletionSource <string>(TaskCreationOptions.RunContinuationsAsynchronously);

            async void EventHandler(object sender, TracingCompleteEventArgs e)
            {
                try
                {
                    var tracingData = await ReadStream(e.Stream, _path).ConfigureAwait(false);

                    _client.TracingComplete -= EventHandler;
                    taskWrapper.TrySetResult(tracingData);
                }
                catch (Exception ex)
                {
                    var message = $"Tracing failed to process the tracing complete. {ex.Message}. {ex.StackTrace}";
                    _logger.LogError(ex, message);
                    _client.Close(message);
                }
            }

            _client.TracingComplete += EventHandler;

            await _client.SendAsync("Tracing.end").ConfigureAwait(false);

            _recording = false;

            return(await taskWrapper.Task.ConfigureAwait(false));
        }
        private async void Client_MessageReceived(object sender, MessageEventArgs e)
        {
            try
            {
                switch (e.MessageID)
                {
                case "Page.frameAttached":
                    OnFrameAttached(
                        e.MessageData.SelectToken(MessageKeys.FrameId).ToObject <string>(),
                        e.MessageData.SelectToken("parentFrameId").ToObject <string>());
                    break;

                case "Page.frameNavigated":
                    await OnFrameNavigatedAsync(e.MessageData.SelectToken(MessageKeys.Frame).ToObject <FramePayload>(true)).ConfigureAwait(false);

                    break;

                case "Page.navigatedWithinDocument":
                    OnFrameNavigatedWithinDocument(e.MessageData.ToObject <NavigatedWithinDocumentResponse>(true));
                    break;

                case "Page.frameDetached":
                    OnFrameDetached(e.MessageData.ToObject <BasicFrameResponse>(true));
                    break;

                case "Page.frameStoppedLoading":
                    OnFrameStoppedLoading(e.MessageData.ToObject <BasicFrameResponse>(true));
                    break;

                case "Runtime.executionContextCreated":
                    await OnExecutionContextCreatedAsync(e.MessageData.SelectToken(MessageKeys.Context).ToObject <ContextPayload>(true));

                    break;

                case "Runtime.executionContextDestroyed":
                    OnExecutionContextDestroyed(e.MessageData.SelectToken(MessageKeys.ExecutionContextId).ToObject <int>());
                    break;

                case "Runtime.executionContextsCleared":
                    OnExecutionContextsCleared();
                    break;

                case "Page.lifecycleEvent":
                    OnLifeCycleEvent(e.MessageData.ToObject <LifecycleEventResponse>(true));
                    break;

                default:
                    break;
                }
            }
            catch (Exception ex)
            {
                var message = $"Connection failed to process {e.MessageID}. {ex.Message}. {ex.StackTrace}";
                _logger.LogError(ex, message);
                _client.Close(message);
            }
        }
Example #5
0
        private async void Client_MessageReceived(object sender, MessageEventArgs e)
        {
            try
            {
                switch (e.MessageID)
                {
                case "Fetch.requestPaused":
                    await OnRequestPausedAsync(e.MessageData.ToObject <FetchRequestPausedResponse>(true)).ConfigureAwait(false);

                    break;

                case "Fetch.authRequired":
                    await OnAuthRequiredAsync(e.MessageData.ToObject <FetchAuthRequiredResponse>(true)).ConfigureAwait(false);

                    break;

                case "Network.requestWillBeSent":
                    await OnRequestWillBeSentAsync(e.MessageData.ToObject <RequestWillBeSentPayload>(true)).ConfigureAwait(false);

                    break;

                case "Network.requestServedFromCache":
                    OnRequestServedFromCache(e.MessageData.ToObject <RequestServedFromCacheResponse>(true));
                    break;

                case "Network.responseReceived":
                    OnResponseReceived(e.MessageData.ToObject <ResponseReceivedResponse>(true));
                    break;

                case "Network.loadingFinished":
                    OnLoadingFinished(e.MessageData.ToObject <LoadingFinishedResponse>(true));
                    break;

                case "Network.loadingFailed":
                    OnLoadingFailed(e.MessageData.ToObject <LoadingFailedResponse>(true));
                    break;
                }
            }
            catch (Exception ex)
            {
                var message = $"NetworkManager failed to process {e.MessageID}. {ex.Message}. {ex.StackTrace}";
                _logger.LogError(ex, message);
                _client.Close(message);
            }
        }