Beispiel #1
0
        /// <summary>
        /// Disposes the Handle. It will mark the JSHandle as disposed and release the <see cref="JSHandle.RemoteObject"/>
        /// </summary>
        /// <returns>The async.</returns>
        public async Task DisposeAsync()
        {
            if (Disposed)
            {
                return;
            }

            Disposed = true;
            await RemoteObjectHelper.ReleaseObjectAsync(Client, RemoteObject, Logger).ConfigureAwait(false);
        }
Beispiel #2
0
        /// <inheritdoc/>
        public override string ToString()
        {
            if (((JObject)RemoteObject)["objectId"] != null)
            {
                var type = RemoteObject.subtype ?? RemoteObject.type;
                return("JSHandle@" + type);
            }

            return("JSHandle:" + RemoteObjectHelper.ValueFromRemoteObject <object>(RemoteObject)?.ToString());
        }
Beispiel #3
0
        /// <summary>
        /// Disposes the Handle. It will mark the JSHandle as disposed and release the <see cref="JSHandle.RemoteObject"/>
        /// </summary>
        /// <returns>The async.</returns>
        public async Task DisposeAsync()
        {
            if (Disposed)
            {
                return;
            }

            Disposed = true;
            await RemoteObjectHelper.ReleaseObject(Client, RemoteObject, Logger);
        }
Beispiel #4
0
        /// <inheritdoc/>
        public override string ToString()
        {
            if ((RemoteObject)[MessageKeys.ObjectId] != null)
            {
                var type = RemoteObject[MessageKeys.Subtype] ?? RemoteObject[MessageKeys.Type];
                return("JSHandle@" + type);
            }

            return("JSHandle:" + RemoteObjectHelper.ValueFromRemoteObject <object>(RemoteObject)?.ToString());
        }
Beispiel #5
0
        /// <inheritdoc/>
        public override string ToString()
        {
            if (RemoteObject.ObjectId != null)
            {
                var type = RemoteObject.Subtype != RemoteObjectSubtype.Other
                    ? RemoteObject.Subtype.ToString()
                    : RemoteObject.Type.ToString();
                return("JSHandle@" + type.ToLower());
            }

            return("JSHandle:" + RemoteObjectHelper.ValueFromRemoteObject <object>(RemoteObject)?.ToString());
        }
Beispiel #6
0
        /// <inheritdoc/>
        public override string ToString()
        {
            if (RemoteObject.ObjectId != null)
            {
                var type = RemoteObject.Subtype != RemoteObjectSubtype.Other
                    ? RemoteObject.Subtype.ToString()
                    : RemoteObject.Type.ToString();
                return("JSHandle@" + type.ToLower(System.Globalization.CultureInfo.CurrentCulture));
            }

            return("JSHandle:" + RemoteObjectHelper.ValueFromRemoteObject <object>(RemoteObject, true)?.ToString());
        }
Beispiel #7
0
        /// <summary>
        /// Returns a JSON representation of the object
        /// </summary>
        /// <typeparam name="T">A strongly typed object to parse to</typeparam>
        /// <returns>Task</returns>
        /// <remarks>
        /// 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
        /// </remarks>
        public async Task <T> JsonValueAsync <T>()
        {
            if (RemoteObject.objectId != null)
            {
                dynamic response = await Client.SendAsync("Runtime.callFunctionOn", new Dictionary <string, object>
                {
                    ["functionDeclaration"] = "function() { return this; }",
                    ["objectId"]            = RemoteObject.objectId,
                    ["returnByValue"]       = true,
                    ["awaitPromise"]        = true
                });

                return((T)RemoteObjectHelper.ValueFromRemoteObject <T>(response.result));
            }

            return((T)RemoteObjectHelper.ValueFromRemoteObject <T>(RemoteObject));
        }
Beispiel #8
0
        /// <summary>
        /// Returns a JSON representation of the object
        /// </summary>
        /// <typeparam name="T">A strongly typed object to parse to</typeparam>
        /// <returns>Task</returns>
        /// <remarks>
        /// 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
        /// </remarks>
        public async Task <T> JsonValueAsync <T>()
        {
            var objectId = RemoteObject.ObjectId;

            if (objectId != null)
            {
                var response = await Client.SendAsync <RuntimeCallFunctionOnResponse>("Runtime.callFunctionOn", new RuntimeCallFunctionOnRequest
                {
                    FunctionDeclaration = "function() { return this; }",
                    ObjectId            = objectId,
                    ReturnByValue       = true,
                    AwaitPromise        = true
                }).ConfigureAwait(false);

                return((T)RemoteObjectHelper.ValueFromRemoteObject <T>(response.Result));
            }

            return((T)RemoteObjectHelper.ValueFromRemoteObject <T>(RemoteObject));
        }
Beispiel #9
0
        /// <summary>
        /// Returns a JSON representation of the object
        /// </summary>
        /// <typeparam name="T">A strongly typed object to parse to</typeparam>
        /// <returns>Task</returns>
        /// <remarks>
        /// 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
        /// </remarks>
        public async Task <T> JsonValueAsync <T>()
        {
            var objectId = RemoteObject[MessageKeys.ObjectId];

            if (objectId != null)
            {
                var response = await Client.SendAsync("Runtime.callFunctionOn", new Dictionary <string, object>
                {
                    ["functionDeclaration"] = "function() { return this; }",
                    [MessageKeys.ObjectId]  = objectId,
                    ["returnByValue"]       = true,
                    ["awaitPromise"]        = true
                }).ConfigureAwait(false);

                return((T)RemoteObjectHelper.ValueFromRemoteObject <T>(response[MessageKeys.Result]));
            }

            return((T)RemoteObjectHelper.ValueFromRemoteObject <T>(RemoteObject));
        }