@@ -21,11 +21,37 @@ public JSHandle(ExecutionContext context, Session client, object remoteObject)
2121 public bool Disposed { get ; set ; }
2222 public dynamic RemoteObject { get ; internal set ; }
2323
24- public Task < Dictionary < string , object > > GetProperty ( string propertyName )
24+ /// <summary>
25+ /// Fetches a single property from the referenced object
26+ /// </summary>
27+ /// <param name="propertyName">property to get</param>
28+ /// <returns>Task of <see cref="JSHandle"/></returns>
29+ public async Task < JSHandle > GetPropertyAsync ( string propertyName )
2530 {
26- throw new System . NotImplementedException ( ) ;
31+ var objectHandle = await ExecutionContext . EvaluateFunctionHandleAsync ( @"(object, propertyName) => {
32+ const result = { __proto__: null};
33+ result[propertyName] = object[propertyName];
34+ return result;
35+ }" , this , propertyName ) ;
36+ var properties = await objectHandle . GetPropertiesAsync ( ) ;
37+ properties . TryGetValue ( propertyName , out var result ) ;
38+ await objectHandle . DisposeAsync ( ) ;
39+ return result ;
2740 }
2841
42+ /// <summary>
43+ /// Returns a <see cref="Dictionary{TKey, TValue}"/> with property names as keys and <see cref="JSHandle"/> instances for the property values.
44+ /// </summary>
45+ /// <returns>Task which resolves to a <see cref="Dictionary{TKey, TValue}"/></returns>
46+ /// <example>
47+ /// <code>
48+ /// var handle = await page.EvaluateExpressionHandle("({window, document})");
49+ /// var properties = await handle.GetPropertiesAsync();
50+ /// var windowHandle = properties["window"];
51+ /// var documentHandle = properties["document"];
52+ /// await handle.DisposeAsync();
53+ /// </code>
54+ /// </example>
2955 public async Task < Dictionary < string , JSHandle > > GetPropertiesAsync ( )
3056 {
3157 var response = await _client . SendAsync ( "Runtime.getProperties" , new
@@ -43,9 +69,24 @@ public async Task<Dictionary<string, JSHandle>> GetPropertiesAsync()
4369 return result ;
4470 }
4571
46- public async Task < object > JsonValue ( ) => await JsonValue < object > ( ) ;
72+ /// <summary>
73+ /// Returns a JSON representation of the object
74+ /// </summary>
75+ /// <returns>Task</returns>
76+ /// <remarks>
77+ /// The method will return an empty JSON if the referenced object is not stringifiable. It will throw an error if the object has circular references
78+ /// </remarks>
79+ public async Task < object > JsonValueAsync ( ) => await JsonValueAsync < object > ( ) ;
4780
48- public async Task < T > JsonValue < T > ( )
81+ /// <summary>
82+ /// Returns a JSON representation of the object
83+ /// </summary>
84+ /// <typeparam name="T">A strongly typed object to parse to</typeparam>
85+ /// <returns>Task</returns>
86+ /// <remarks>
87+ /// The method will return an empty JSON if the referenced object is not stringifiable. It will throw an error if the object has circular references
88+ /// </remarks>
89+ public async Task < T > JsonValueAsync < T > ( )
4990 {
5091 if ( RemoteObject . objectId != null )
5192 {
@@ -83,7 +124,7 @@ public override string ToString()
83124 return "JSHandle@" + type ;
84125 }
85126
86- return Helper . ValueFromRemoteObject < object > ( RemoteObject ) ? . ToString ( ) ;
127+ return "JSHandle:" + Helper . ValueFromRemoteObject < object > ( RemoteObject ) ? . ToString ( ) ;
87128 }
88129
89130 internal object FormatArgument ( ExecutionContext context )
0 commit comments