Ejemplo n.º 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();
        }
Ejemplo n.º 2
0
 /// <summary>
 /// Gets the <see cref="ExecutionContext"/> associated with the frame.
 /// </summary>
 /// <returns><see cref="ExecutionContext"/> associated with the frame.</returns>
 public Task <ExecutionContext> GetExecutionContextAsync() => _mainWorld.GetExecutionContextAsync();