public async Task <dynamic> QueryObjects(JSHandle prototypeHandle) { if (prototypeHandle.Disposed) { throw new ArgumentException("prototypeHandle is disposed", nameof(prototypeHandle)); } if (!((IDictionary <string, object>)prototypeHandle.RemoteObject).ContainsKey("objectId")) { throw new ArgumentException("Prototype JSHandle must not be referencing primitive value", nameof(prototypeHandle)); } dynamic response = await _client.SendAsync("Runtime.queryObjects", new Dictionary <string, object>() { { "prototypeObjectId", prototypeHandle.RemoteObject.objectId } }); return(ObjectHandleFactory(response.objects)); }
/// <summary> /// The method iterates JavaScript heap and finds all the objects with the given prototype. /// </summary> /// <returns>A task which resolves to a handle to an array of objects with this prototype.</returns> /// <param name="prototypeHandle">A handle to the object prototype.</param> public async Task <JSHandle> QueryObjectsAsync(JSHandle prototypeHandle) { if (prototypeHandle == null) { throw new ArgumentNullException(nameof(prototypeHandle)); } if (prototypeHandle.Disposed) { throw new PuppeteerException("Prototype JSHandle is disposed!"); } if (prototypeHandle.RemoteObject.ObjectId == null) { throw new PuppeteerException("Prototype JSHandle must not be referencing primitive value"); } var response = await _client.SendAsync <RuntimeQueryObjectsResponse>("Runtime.queryObjects", new RuntimeQueryObjectsRequest { PrototypeObjectId = prototypeHandle.RemoteObject.ObjectId }).ConfigureAwait(false); return(CreateJSHandle(response.Objects)); }
internal async Task Rerun() { var runCount = Interlocked.Increment(ref _runCount); JSHandle success = null; Exception exception = null; var context = await _world.GetExecutionContextAsync().ConfigureAwait(false); try { success = await context.EvaluateFunctionHandleAsync(WaitForPredicatePageFunction, new object[] { _predicateBody, _pollingInterval ?? (object)_polling, _timeout }.Concat(_args).ToArray()).ConfigureAwait(false); } catch (Exception ex) { exception = ex; } if (_terminated || runCount != _runCount) { if (success != null) { await success.DisposeAsync().ConfigureAwait(false); } return; } if (exception == null && await _world.EvaluateFunctionAsync <bool>("s => !s", success) .ContinueWith(task => task.IsFaulted || task.Result) .ConfigureAwait(false)) { if (success != null) { await success.DisposeAsync().ConfigureAwait(false); } return; } if (exception?.Message.Contains("Execution context was destroyed") == true) { _ = Rerun(); return; } if (exception?.Message.Contains("Cannot find context with specified id") == true) { return; } if (exception != null) { _taskCompletion.TrySetException(exception); } else { _taskCompletion.TrySetResult(success); } Cleanup(); }
public async Task <JSHandle> QueryObjects(JSHandle prototypeHandle) { var context = await MainFrame.GetExecutionContextAsync(); return(await context.QueryObjects(prototypeHandle)); }