public async Task <BrowserResult> InvokeAsync(BrowserOptions options, CancellationToken cancellationToken = new CancellationToken())
        {
            if (options == null)
            {
                throw new ArgumentException("Options cannot be null", nameof(options));
            }

            using var listener = new LoopbackHttpListener(Port, _path);
            OpenBrowser.OpenBrowser(options.StartUrl, UserName, Password);

            try
            {
                var result = await listener.WaitForCallbackAsync().ConfigureAwait(false);

                if (string.IsNullOrWhiteSpace(result))
                {
                    return(new BrowserResult {
                        ResultType = BrowserResultType.UnknownError, Error = "Empty response."
                    });
                }

                return(new BrowserResult {
                    Response = result, ResultType = BrowserResultType.Success
                });
            }
            catch (TaskCanceledException ex)
            {
                return(new BrowserResult {
                    ResultType = BrowserResultType.Timeout, Error = ex.Message
                });
            }
        }
Beispiel #2
0
        public async Task <BrowserResult> InvokeAsync(BrowserOptions options)
        {
            using (var listener = new LoopbackHttpListener(Port, _path))
            {
                OpenBrowser(options.StartUrl);

                try
                {
                    var result = await listener.WaitForCallbackAsync();

                    if (String.IsNullOrWhiteSpace(result))
                    {
                        return(new BrowserResult {
                            ResultType = BrowserResultType.UnknownError, Error = "Empty response."
                        });
                    }

                    return(new BrowserResult {
                        Response = result, ResultType = BrowserResultType.Success
                    });
                }
                catch (TaskCanceledException ex)
                {
                    return(new BrowserResult {
                        ResultType = BrowserResultType.Timeout, Error = ex.Message
                    });
                }
                catch (Exception ex)
                {
                    return(new BrowserResult {
                        ResultType = BrowserResultType.UnknownError, Error = ex.Message
                    });
                }
            }
        }