- 
          
 - 
                Notifications
    
You must be signed in to change notification settings  - Fork 8.6k
 
          [dotnet] Switch DevTools response JSON parsing to JsonElement
          #14990
        
          New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
          PR Reviewer Guide 🔍Here are some key observations to aid the review process: 
  | 
    
          PR Code Suggestions ✨Explore these optional code suggestions: 
  | 
    
          
 I still don't see how, can you please elaborate more? 
  | 
    
| 
           
 This PR is a first step towards handling the invalid JSON which CDP sometimes returns.  | 
    
| 
           When I was migrating from   | 
    
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thx @RenderMichael for your contribution!
User description
Thanks for contributing to Selenium!
A PR well described will help maintainers to quickly review and merge it
Before submitting your PR, please check our contributing guidelines.
Avoid large PRs, help reviewers by making them as simple and short as possible.
Description
Switches JSON response parsing in DevTools from mutable
JsonNodeto immutableJsonElement.Motivation and Context
In general,
JsonElementis preferred if the JSON is not being mutated. But the true motivation is from #14972.JsonElementis a lot more forgiving of imperfect json (it allows multiple properties with the same name, it doesn't throw exceptions on invalid UTF-16 before the deserialization converters apply, etc).This will allow us to Eventually fortify the code against invalid JSON, which is the root cause of #14903.
Types of changes
Checklist
PR Type
Bug fix, Enhancement
Description
JsonNodeto immutableJsonElementacross multiple filesJsonElementwhich is more forgiving of imperfect JSONChanges walkthrough 📝
DevToolsCommandData.cs
Switch Result property to JsonElement typedotnet/src/webdriver/DevTools/DevToolsCommandData.cs
Resultproperty type fromJsonNodetoJsonElementDevToolsSession.cs
Refactor JSON handling to use JsonElementdotnet/src/webdriver/DevTools/DevToolsSession.cs
JsonElementinstead ofJsonNodeDevToolsSessionEventReceivedEventArgs.cs
Update EventData to use JsonElementdotnet/src/webdriver/DevTools/DevToolsSessionEventReceivedEventArgs.cs
EventDataproperty type fromJsonNodetoJsonElementIDevToolsSession.cs
Update SendCommand return type to JsonElementdotnet/src/webdriver/DevTools/IDevToolsSession.cs
SendCommandfromJsonNodetoJsonElement?