Пример #1
0
        public async Task <BrowserResult> InvokeAsync(BrowserOptions options, CancellationToken cancellationToken = default)
        {
            _options = options;

            var window = new Window()
            {
                Width  = 900,
                Height = 625,
                Title  = "VPS Demo Login"
            };

            // Note: Unfortunately, WebBrowser is very limited and does not give sufficient information for
            //   robust error handling. The alternative is to use a system browser or third party embedded
            //   library (which tend to balloon the size of your application and are complicated).
            WebBrowserHelper.ClearCache();
            var webBrowser = new WebBrowser();

            var signal = new SemaphoreSlim(0, 1);

            var result = new BrowserResult()
            {
                ResultType = BrowserResultType.UserCancel
            };

            webBrowser.Navigating += (s, e) =>
            {
                if (BrowserIsNavigatingToRedirectUri(e.Uri))
                {
                    e.Cancel = true;

                    result = new BrowserResult()
                    {
                        ResultType = BrowserResultType.Success,
                        Response   = e.Uri.AbsoluteUri
                    };

                    signal.Release();

                    window.Close();
                }
            };

            window.Closing += (s, e) =>
            {
                signal.Release();
            };

            window.Content = webBrowser;
            window.Show();
            webBrowser.Source = new Uri(_options.StartUrl);

            await signal.WaitAsync();

            return(result);
        }
Пример #2
0
        public EmbeddedBrowser()
        {
            WinInetHelper.SupressCookiePersist();

            result = new BrowserResult();
            SetDefaultResult();

            Window = new Window()
            {
                Width  = 600,
                Height = 800,
                WindowStartupLocation = WindowStartupLocation.CenterScreen,
            };
            Window.Closing += Window_Closing;

            // Create WebBrowser
            webBrowser             = new WebBrowser();
            webBrowser.Navigating += WebBrowser_Navigating;

            // Add browser as content of the window
            Window.Content = webBrowser;
        }