1919
2020using  System ; 
2121using  System . Collections . Concurrent ; 
22+ using  System . Text . Json ; 
23+ using  System . Text . Json . Serialization ; 
2224using  System . Threading ; 
2325using  System . Threading . Tasks ; 
2426using  OpenQA . Selenium . BiDi . Communication ; 
27+ using  OpenQA . Selenium . BiDi . Communication . Json . Converters ; 
2528
2629namespace  OpenQA . Selenium . BiDi ; 
2730
2831public  sealed  class  BiDi  :  IAsyncDisposable 
2932{ 
3033    private  readonly  Broker  _broker ; 
34+     private  readonly  JsonSerializerOptions  _jsonOptions ; 
3135
3236    private  readonly  ConcurrentDictionary < Type ,  Module >  _modules  =  [ ] ; 
3337
3438    private  BiDi ( string  url ) 
3539    { 
3640        var  uri  =  new  Uri ( url ) ; 
3741
38-         _broker  =  new  Broker ( this ,  uri ) ; 
42+         _jsonOptions  =  new  JsonSerializerOptions 
43+         { 
44+             PropertyNameCaseInsensitive  =  true , 
45+             PropertyNamingPolicy  =  JsonNamingPolicy . CamelCase , 
46+             DefaultIgnoreCondition  =  JsonIgnoreCondition . WhenWritingNull , 
47+ 
48+             // BiDi returns special numbers such as "NaN" as strings 
49+             // Additionally, -0 is returned as a string "-0" 
50+             NumberHandling  =  JsonNumberHandling . AllowNamedFloatingPointLiterals  |  JsonNumberHandling . AllowReadingFromString , 
51+             Converters  = 
52+             { 
53+                 new  BrowsingContextConverter ( this ) , 
54+                 new  BrowserUserContextConverter ( this ) , 
55+                 new  CollectorConverter ( this ) , 
56+                 new  InterceptConverter ( this ) , 
57+                 new  HandleConverter ( this ) , 
58+                 new  InternalIdConverter ( this ) , 
59+                 new  PreloadScriptConverter ( this ) , 
60+                 new  RealmConverter ( this ) , 
61+                 new  DateTimeOffsetConverter ( ) , 
62+                 new  WebExtensionConverter ( this ) , 
63+             } 
64+         } ; 
65+ 
66+         _broker  =  new  Broker ( this ,  uri ,  _jsonOptions ) ; 
3967    } 
4068
4169    internal  Session . SessionModule  SessionModule  =>  AsModule < Session . SessionModule > ( ) ; 
@@ -60,7 +88,7 @@ private BiDi(string url)
6088
6189    public  TModule  AsModule < TModule > ( )  where  TModule  :  Module ,  new ( ) 
6290    { 
63-         return  ( TModule ) _modules . GetOrAdd ( typeof ( TModule ) ,  _ =>  Module . Create < TModule > ( _broker ) ) ; 
91+         return  ( TModule ) _modules . GetOrAdd ( typeof ( TModule ) ,  _ =>  Module . Create < TModule > ( this ,   _broker ,   _jsonOptions ) ) ; 
6492    } 
6593
6694    public  Task < Session . StatusResult >  StatusAsync ( ) 
0 commit comments