|
16 | 16 | // limitations under the License.
|
17 | 17 | // </copyright>
|
18 | 18 |
|
| 19 | +using OpenQA.Selenium.Internal.Logging; |
19 | 20 | using System;
|
20 | 21 | using System.Collections.Concurrent;
|
21 | 22 | using System.Globalization;
|
@@ -56,6 +57,8 @@ public class DevToolsSession : IDevToolsSession
|
56 | 57 | private DevToolsDomains domains;
|
57 | 58 | private readonly DevToolsOptions options;
|
58 | 59 |
|
| 60 | + private readonly static ILogger logger = Internal.Logging.Log.GetLogger<DevToolsSession>(); |
| 61 | + |
59 | 62 | /// <summary>
|
60 | 63 | /// Initializes a new instance of the DevToolsSession class, using the specified WebSocket endpoint.
|
61 | 64 | /// </summary>
|
@@ -272,6 +275,11 @@ public T GetVersionSpecificDomains<T>() where T : DevToolsSessionDomains
|
272 | 275 |
|
273 | 276 | if (this.connection != null && this.connection.IsActive)
|
274 | 277 | {
|
| 278 | + if (logger.IsEnabled(LogEventLevel.Trace)) |
| 279 | + { |
| 280 | + logger.Trace($"CDP SND >> {message.CommandId} {message.CommandName}: {commandParameters.ToJsonString()}"); |
| 281 | + } |
| 282 | + |
275 | 283 | LogTrace("Sending {0} {1}: {2}", message.CommandId, message.CommandName, commandParameters.ToString());
|
276 | 284 |
|
277 | 285 | string contents = JsonSerializer.Serialize(message);
|
@@ -540,6 +548,11 @@ private void MonitorMessageQueue()
|
540 | 548 |
|
541 | 549 | private void ProcessMessage(string message)
|
542 | 550 | {
|
| 551 | + if (logger.IsEnabled(LogEventLevel.Trace)) |
| 552 | + { |
| 553 | + logger.Trace($"CDP RCV << {message}"); |
| 554 | + } |
| 555 | + |
543 | 556 | var messageObject = JsonObject.Parse(message).AsObject();
|
544 | 557 |
|
545 | 558 | if (messageObject.TryGetPropertyValue("id", out var idProperty))
|
@@ -583,7 +596,22 @@ private void ProcessMessage(string message)
|
583 | 596 | // DevTools commands that may be sent in the body of the attached
|
584 | 597 | // event handler. If thread pool starvation seems to become a problem,
|
585 | 598 | // we can switch to a channel-based queue.
|
586 |
| - Task.Run(() => OnDevToolsEventReceived(new DevToolsEventReceivedEventArgs(methodParts[0], methodParts[1], eventData))); |
| 599 | + Task.Run(() => |
| 600 | + { |
| 601 | + try |
| 602 | + { |
| 603 | + OnDevToolsEventReceived(new DevToolsEventReceivedEventArgs(methodParts[0], methodParts[1], eventData)); |
| 604 | + } |
| 605 | + catch (Exception ex) |
| 606 | + { |
| 607 | + if (logger.IsEnabled(LogEventLevel.Warn)) |
| 608 | + { |
| 609 | + logger.Warn($"CDP VNT ^^ Unhandled error occured in event handler of '{method}' method. {ex}"); |
| 610 | + } |
| 611 | + |
| 612 | + throw; |
| 613 | + } |
| 614 | + }); |
587 | 615 |
|
588 | 616 | return;
|
589 | 617 | }
|
|
0 commit comments