Beispiel #1
0
        internal async Task Rerun()
        {
            var       runCount  = Interlocked.Increment(ref _runCount);
            JSHandle  success   = null;
            Exception exception = null;

            var context = await _domWorld.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 _domWorld.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)
            {
                return;
            }

            if (exception?.Message.Contains("Cannot find context with specified id") == true)
            {
                return;
            }

            if (exception != null)
            {
                _taskCompletion.SetException(exception);
            }
            else
            {
                _taskCompletion.TrySetResult(success);
            }
            Cleanup();
        }
Beispiel #2
0
 /// <summary>
 /// Executes a function in browser context
 /// </summary>
 /// <param name="script">Script to be evaluated in browser context</param>
 /// <param name="args">Arguments to pass to script</param>
 /// <remarks>
 /// If the script, returns a Promise, then the method would wait for the promise to resolve and return its value.
 /// <see cref="JSHandle"/> instances can be passed as arguments
 /// </remarks>
 /// <returns>Task which resolves to script return value</returns>
 /// <seealso cref="EvaluateExpressionAsync{T}(string)"/>
 /// <seealso cref="Page.EvaluateFunctionAsync{T}(string, object[])"/>
 public Task <JToken> EvaluateFunctionAsync(string script, params object[] args) => _mainWorld.EvaluateFunctionAsync(script, args);