Exemplo n.º 1
0
        /// <inheritdoc cref="IFrame.GoToAsync(string, GoToOptions)"/>
        public async Task <IResponse> GoToAsync(string url, GoToOptions options = null)
        {
            Page.PageState.ExtraHTTPHeaders.TryGetValue("referer", out string referer);

            if (options?.Referer != null)
            {
                if (referer != null && referer != options.Referer)
                {
                    throw new ArgumentException("\"referer\" is already specified as extra HTTP header");
                }

                referer = options.Referer;
            }

            using var watcher = new LifecycleWatcher(this, options);

            try
            {
                var navigateTask = Page.Delegate.NavigateFrameAsync(this, url, referer);
                var task         = await Task.WhenAny(
                    watcher.TimeoutOrTerminationTask,
                    navigateTask).ConfigureAwait(false);

                await task.ConfigureAwait(false);

                var tasks = new List <Task>()
                {
                    watcher.TimeoutOrTerminationTask
                };
                if (!string.IsNullOrEmpty(navigateTask.Result.NewDocumentId))
                {
                    watcher.SetExpectedDocumentId(navigateTask.Result.NewDocumentId, url);
                    tasks.Add(watcher.NewDocumentNavigationTask);
                }
                else if (navigateTask.Result.IsSameDocument)
                {
                    tasks.Add(watcher.SameDocumentNavigationTask);
                }
                else
                {
                    tasks.AddRange(new[] { watcher.SameDocumentNavigationTask, watcher.NewDocumentNavigationTask });
                }

                task = await Task.WhenAny(tasks).ConfigureAwait(false);

                await task.ConfigureAwait(false);
            }
            catch (Exception ex)
            {
                throw new NavigationException(ex.Message, ex);
            }

            return(watcher.NavigationResponse);
        }
Exemplo n.º 2
0
 /// <inheritdoc />
 public async Task <IResponse> GoToAsync(string url, GoToOptions options = null)
 => (await _channel.GoToAsync(url, options).ConfigureAwait(false)).Object;
Exemplo n.º 3
0
 /// <inheritdoc />
 public Task <IResponse> GoToAsync(string url, GoToOptions options = null) => MainFrame.GoToAsync(url, options);