public LifecycleWatcher(Frame frame, NavigationOptions options) { _options = options != null && options is NavigationOptions ? (WaitForNavigationOptions)options : new WaitForNavigationOptions(); _frame = frame; _expectedLifecycle = (_options.WaitUntil ?? _defaultWaitUntil).Select(w => { string protocolEvent = _protocolLifecycle.GetValueOrDefault(w); if (protocolEvent == null) { throw new PlaywrightSharpException($"Unknown value for options.waitUntil: {w}"); } return(protocolEvent); }); _timeout = frame.Page.DefaultNavigationTimeout; _frame = frame; _sameDocumentNavigationTaskWrapper = new TaskCompletionSource <bool>(TaskCreationOptions.RunContinuationsAsynchronously); _lifecycleTaskWrapper = new TaskCompletionSource <bool>(TaskCreationOptions.RunContinuationsAsynchronously); _newDocumentNavigationTaskWrapper = new TaskCompletionSource <bool>(TaskCreationOptions.RunContinuationsAsynchronously); _terminationTaskWrapper = new TaskCompletionSource <bool>(TaskCreationOptions.RunContinuationsAsynchronously); _frame.Page.FrameManager.LifecycleWatchers.Add(this); CheckLifecycleComplete(); }
public LifecycleWatcher(Frame frame, NavigationOptions options, CancellationToken token = default) { _options = options != null ? options as WaitForNavigationOptions ?? new WaitForNavigationOptions(options) : new WaitForNavigationOptions(); _expectedLifecycle = _options.WaitUntil ?? _defaultWaitUntil; _timeout = _options?.Timeout ?? frame.Page.DefaultNavigationTimeout; _frame = frame; _sameDocumentNavigationTaskWrapper = new TaskCompletionSource <bool>(TaskCreationOptions.RunContinuationsAsynchronously); _lifecycleTaskWrapper = new TaskCompletionSource <bool>(TaskCreationOptions.RunContinuationsAsynchronously); _newDocumentNavigationTaskWrapper = new TaskCompletionSource <bool>(TaskCreationOptions.RunContinuationsAsynchronously); _terminationTaskWrapper = new TaskCompletionSource <bool>(TaskCreationOptions.RunContinuationsAsynchronously); _frame.Page.FrameManager.LifecycleWatchers.Add(this); _token = token; _frame.Page.ClientDisconnected += (sender, args) => _terminationTaskWrapper.TrySetException(new PlaywrightSharpException("Client disconnected")); CheckLifecycleComplete(); }
/// <inheritdoc cref="IFrame.WaitForNavigationAsync(WaitForNavigationOptions, CancellationToken)"/> public async Task <IResponse> WaitForNavigationAsync(WaitForNavigationOptions options = null, CancellationToken token = default) { using var watcher = new LifecycleWatcher(this, options); var errorTask = watcher.TimeoutOrTerminationTask; await Task.WhenAny( errorTask, watcher.SameDocumentNavigationTask, watcher.NewDocumentNavigationTask).ConfigureAwait(false); if (errorTask.IsCompleted) { await errorTask.ConfigureAwait(false); } return(await watcher.NavigationResponseTask.ConfigureAwait(false)); }
/// <inheritdoc /> public Task <IResponse> WaitForNavigationAsync(WaitForNavigationOptions options = null, CancellationToken token = default) => throw new NotImplementedException();
/// <inheritdoc cref="IFrame.WaitForNavigationAsync(WaitForNavigationOptions)"/> public Task <IResponse> WaitForNavigationAsync(WaitForNavigationOptions options = null) { throw new System.NotImplementedException(); }