private void LicenseChecker_Loaded(object sender, RoutedEventArgs e) { ToolbarForLicenseChecker.Visibility = Visibility.Collapsed; ButtonContinue.Visibility = Visibility.Collapsed; ButtonKeyActivation.Visibility = Visibility.Collapsed; ButtonHobbyist.Visibility = Visibility.Collapsed; ToolbarForLicenseChecker.Visibility = Visibility.Collapsed; ButtonGoToLoginPage.Visibility = Visibility.Collapsed; LicenseCheckerBrowserContainer.Visibility = Visibility.Collapsed; BrowserContextParams browserParameters = new BrowserContextParams("data-dir-license") { StorageType = StorageType.DISK }; BrowserContext browserContext = new BrowserContext(browserParameters); Browser = BrowserFactory.Create(browserContext, BrowserType.LIGHTWEIGHT); CookiesHelper.LoadCookies(BrowserView, CSHTML5_COOKIES_URL, NAME_FOR_STORING_COOKIES); CookiesHelper.LoadMicrosoftCookies(BrowserView, NAME_FOR_STORING_COOKIES); BrowserView = new WPFBrowserView(Browser); LicenseCheckerBrowserContainer.Child = BrowserView; // we check if a commercial key is activated and we add it to the cookie before loading the login URL if (IsCommercialKeyActivated()) { SetKeyGuidAsCookie(); // we set the key guid as a session cookie so the website know we have an activated key } // we add an handler for browser error (eg: internet down, website down, page not found...) Browser.FailLoadingFrameEvent += OnFailLoadingFrameEvent; //To Do: find a better way of managing those error Browser.LoadURL(LoginURL); Enable = true; BrowserView.DocumentLoadedInMainFrameEvent += (s1, e1) => { // We use a dispatcher to go back to thread in charge of the UI. MainWindow.Dispatcher.BeginInvoke((Action)(() => { //if (_javaScriptExecutionHandler == null) // _javaScriptExecutionHandler = new JavaScriptExecutionHandler(MainWebBrowser); //dynamic rootElement = _javaScriptExecutionHandler.ExecuteJavaScriptWithResult(@"document.getElementByIdSafe(""cshtml5-root"");"); //MessageBox.Show(rootElement.ToString()); //todo: verify that we are not on an outside page (eg. Azure Active Directory login page) OnLoaded(); }), DispatcherPriority.ApplicationIdle); }; }