@@ -168,7 +168,7 @@ public T GetVersionSpecificDomains<T>() where T : DevToolsSessionDomains
168168 throw new InvalidOperationException ( $ "Type { command . GetType ( ) } does not correspond to a known command response type.") ;
169169 }
170170
171- return result . Deserialize ( commandResponseType ) as ICommandResponse < TCommand > ;
171+ return result . Value . Deserialize ( commandResponseType ) as ICommandResponse < TCommand > ;
172172 }
173173
174174 /// <summary>
@@ -201,7 +201,7 @@ public T GetVersionSpecificDomains<T>() where T : DevToolsSessionDomains
201201 throw new InvalidOperationException ( $ "Type { typeof ( TCommand ) } does not correspond to a known command response type.") ;
202202 }
203203
204- return result . Deserialize ( commandResponseType ) as ICommandResponse < TCommand > ;
204+ return result . Value . Deserialize ( commandResponseType ) as ICommandResponse < TCommand > ;
205205 }
206206
207207 /// <summary>
@@ -230,7 +230,7 @@ public T GetVersionSpecificDomains<T>() where T : DevToolsSessionDomains
230230 return default ( TCommandResponse ) ;
231231 }
232232
233- return result . Deserialize < TCommandResponse > ( ) ;
233+ return result . Value . Deserialize < TCommandResponse > ( ) ;
234234 }
235235
236236 /// <summary>
@@ -243,7 +243,7 @@ public T GetVersionSpecificDomains<T>() where T : DevToolsSessionDomains
243243 /// <param name="throwExceptionIfResponseNotReceived"><see langword="true"/> to throw an exception if a response is not received; otherwise, <see langword="false"/>.</param>
244244 /// <returns>The command response object implementing the <see cref="ICommandResponse{T}"/> interface.</returns>
245245 //[DebuggerStepThrough]
246- public async Task < JsonNode > SendCommand ( string commandName , JsonNode commandParameters , CancellationToken cancellationToken = default ( CancellationToken ) , int ? millisecondsTimeout = null , bool throwExceptionIfResponseNotReceived = true )
246+ public async Task < JsonElement ? > SendCommand ( string commandName , JsonNode commandParameters , CancellationToken cancellationToken = default ( CancellationToken ) , int ? millisecondsTimeout = null , bool throwExceptionIfResponseNotReceived = true )
247247 {
248248 if ( this . attachedTargetId == null )
249249 {
@@ -265,7 +265,7 @@ public T GetVersionSpecificDomains<T>() where T : DevToolsSessionDomains
265265 /// <param name="throwExceptionIfResponseNotReceived"><see langword="true"/> to throw an exception if a response is not received; otherwise, <see langword="false"/>.</param>
266266 /// <returns>The command response object implementing the <see cref="ICommandResponse{T}"/> interface.</returns>
267267 //[DebuggerStepThrough]
268- public async Task < JsonNode > SendCommand ( string commandName , string sessionId , JsonNode commandParameters , CancellationToken cancellationToken = default ( CancellationToken ) , int ? millisecondsTimeout = null , bool throwExceptionIfResponseNotReceived = true )
268+ public async Task < JsonElement ? > SendCommand ( string commandName , string sessionId , JsonNode commandParameters , CancellationToken cancellationToken = default ( CancellationToken ) , int ? millisecondsTimeout = null , bool throwExceptionIfResponseNotReceived = true )
269269 {
270270 if ( millisecondsTimeout . HasValue == false )
271271 {
@@ -298,8 +298,8 @@ public T GetVersionSpecificDomains<T>() where T : DevToolsSessionDomains
298298 {
299299 if ( modified . IsError )
300300 {
301- var errorMessage = modified . Result [ "message" ] . GetValue < string > ( ) ;
302- var errorData = modified . Result [ "data" ] ? . GetValue < string > ( ) ;
301+ var errorMessage = modified . Result . GetProperty ( "message" ) . GetString ( ) ;
302+ var errorData = modified . Result . TryGetProperty ( "data" , out var data ) ? data . GetString ( ) : null ;
303303
304304 var exceptionMessage = $ "{ commandName } : { errorMessage } ";
305305 if ( ! string . IsNullOrWhiteSpace ( errorData ) )
@@ -310,7 +310,7 @@ public T GetVersionSpecificDomains<T>() where T : DevToolsSessionDomains
310310 LogTrace ( "Recieved Error Response {0}: {1} {2}" , modified . CommandId , message , errorData ) ;
311311 throw new CommandResponseException ( exceptionMessage )
312312 {
313- Code = modified . Result [ "code" ] ? . GetValue < long > ( ) ?? - 1
313+ Code = modified . Result . TryGetProperty ( "code" , out var code ) ? code . GetInt64 ( ) : - 1
314314 } ;
315315 }
316316
@@ -559,23 +559,27 @@ private void ProcessMessage(string message)
559559 logger . Trace ( $ "CDP RCV << { message } ") ;
560560 }
561561
562- var messageObject = JsonObject . Parse ( message ) . AsObject ( ) ;
562+ JsonElement messageObject ;
563+ using ( var doc = JsonDocument . Parse ( message ) )
564+ {
565+ messageObject = doc . RootElement . Clone ( ) ;
566+ }
563567
564- if ( messageObject . TryGetPropertyValue ( "id" , out var idProperty ) )
568+ if ( messageObject . TryGetProperty ( "id" , out var idProperty ) )
565569 {
566- long commandId = ( long ) idProperty ;
570+ long commandId = idProperty . GetInt64 ( ) ;
567571
568572 DevToolsCommandData commandInfo ;
569573 if ( this . pendingCommands . TryGetValue ( commandId , out commandInfo ) )
570574 {
571- if ( messageObject . TryGetPropertyValue ( "error" , out var errorProperty ) )
575+ if ( messageObject . TryGetProperty ( "error" , out var errorProperty ) )
572576 {
573577 commandInfo . IsError = true ;
574578 commandInfo . Result = errorProperty ;
575579 }
576580 else
577581 {
578- commandInfo . Result = messageObject [ "result" ] ;
582+ commandInfo . Result = messageObject . GetProperty ( "result" ) ;
579583 LogTrace ( "Recieved Response {0}: {1}" , commandId , commandInfo . Result . ToString ( ) ) ;
580584 }
581585
@@ -594,11 +598,11 @@ private void ProcessMessage(string message)
594598 return ;
595599 }
596600
597- if ( messageObject . TryGetPropertyValue ( "method" , out var methodProperty ) )
601+ if ( messageObject . TryGetProperty ( "method" , out var methodProperty ) )
598602 {
599- var method = ( string ) methodProperty ;
603+ var method = methodProperty . GetString ( ) ;
600604 var methodParts = method . Split ( new char [ ] { '.' } , 2 ) ;
601- var eventData = messageObject [ "params" ] ;
605+ var eventData = messageObject . GetProperty ( "params" ) ;
602606
603607 LogTrace ( "Recieved Event {0}: {1}" , method , eventData . ToString ( ) ) ;
604608
0 commit comments