public VkPhoneConfirmForm(WebProxy proxy) { InitializeComponent(); BrowserView browser = null; if (proxy != null) { var dataDir = Path.GetFullPath("chromium-data"); var contextParams = new BrowserContextParams(dataDir); var proxyRules = "https=" + proxy.Address.Host + ":" + proxy.Address.Port; contextParams.ProxyConfig = new CustomProxyConfig(proxyRules); browser = new WinFormsBrowserView( BrowserFactory.Create( new BrowserContext(contextParams), BrowserType.LIGHTWEIGHT)); } else { browser = new WinFormsBrowserView(); } wb = (Control)browser; this.Controls.Add(wb); wb.Dock = DockStyle.Fill; browser.Browser.LoadURL("https://vk.com"); }
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); }; }
static void Main(string[] args) { String dataDir = Path.GetFullPath("chromium-data"); BrowserContextParams contextParams = new BrowserContextParams(dataDir); // Browser will automatically detect proxy settings. // contextParams.ProxyConfig = new AutoDetectProxyConfig(); // Browser will not use a proxy server. // contextParams.ProxyConfig = new DirectProxyConfig(); // Browser will use proxy settings received from proxy auto-config (PAC) file. //contextParams.ProxyConfig = new URLProxyConfig("<pac-file-url>"); // Browser will use custom user's proxy settings. String proxyRules = "http=foo:80;https=foo:80;ftp=foo:80;socks=foo:80"; String exceptions = "<local>"; // bypass proxy server for local web pages contextParams.ProxyConfig = new CustomProxyConfig(proxyRules, exceptions); // Creates Browser instance with context configured to use specified proxy settings. Browser browser = BrowserFactory.Create(new BrowserContext(contextParams)); // Handle proxy authorization. browser.Context.NetworkService.NetworkDelegate = new MyNetworkDelegate(); ManualResetEvent loadedEvent = new ManualResetEvent(false); ManualResetEvent failedEvent = new ManualResetEvent(false); browser.FinishLoadingFrameEvent += delegate(object sender, FinishLoadingEventArgs e) { if (e.IsMainFrame) { Log(e.Browser, "FINISH - " + e.Browser.Title); loadedEvent.Set(); failedEvent.Set(); } }; browser.FailLoadingFrameEvent += delegate(object sender, FailLoadingEventArgs e) { if (e.IsMainFrame) { Log(e.Browser, "FAIL - " + e.ErrorDescription); failedEvent.Set(); } }; browser.LoadURL("https://www.teamdev.com/"); failedEvent.WaitOne(new TimeSpan(0, 0, 30)); loadedEvent.WaitOne(new TimeSpan(0, 0, 30)); failedEvent.Reset(); loadedEvent.Reset(); browser.Context.ProxyConfig = new SystemProxyConfig(); browser.LoadURL("https://www.teamdev.com/"); failedEvent.WaitOne(new TimeSpan(0, 0, 30)); loadedEvent.WaitOne(new TimeSpan(0, 0, 30)); failedEvent.Reset(); loadedEvent.Reset(); browser.Context.ProxyConfig = new AutoDetectProxyConfig(); browser.LoadURL("https://www.teamdev.com/"); failedEvent.WaitOne(new TimeSpan(0, 0, 30)); loadedEvent.WaitOne(new TimeSpan(0, 0, 30)); failedEvent.Reset(); loadedEvent.Reset(); browser.Context.ProxyConfig = new DirectProxyConfig(); browser.LoadURL("https://www.teamdev.com/"); failedEvent.WaitOne(new TimeSpan(0, 0, 30)); loadedEvent.WaitOne(new TimeSpan(0, 0, 30)); failedEvent.Reset(); loadedEvent.Reset(); browser.Context.ProxyConfig = new URLProxyConfig("http://test/");; browser.LoadURL("https://www.teamdev.com/"); failedEvent.WaitOne(new TimeSpan(0, 0, 30)); loadedEvent.WaitOne(new TimeSpan(0, 0, 30)); failedEvent.Reset(); loadedEvent.Reset(); browser.Context.ProxyConfig = new CustomProxyConfig(proxyRules, exceptions); browser.LoadURL("https://www.teamdev.com/"); failedEvent.WaitOne(new TimeSpan(0, 0, 30)); loadedEvent.WaitOne(new TimeSpan(0, 0, 30)); failedEvent.Reset(); loadedEvent.Reset(); browser.Context.ProxyConfig = new CustomProxyConfig(proxyRules, "https://www.teamdev.com"); browser.LoadURL("https://www.teamdev.com/"); failedEvent.WaitOne(new TimeSpan(0, 0, 30)); loadedEvent.WaitOne(new TimeSpan(0, 0, 30)); failedEvent.Reset(); loadedEvent.Reset(); Thread.Sleep(new TimeSpan(0, 0, 30)); browser.Dispose(); }