/// <summary> /// Opens a new browser window /// <para>Note: If changing browser types, all windows opened by the previous type must be closed first</para> /// </summary> /// <param name="url">The URL for the window to navigate to</param> /// <param name="webBrowserType">The type of browser to open (e.g. "IE", "Chrome", "Firefox", "Safari")</param> /// <param name="closeAllOtherBrowserWindows">If true, all browsers of type webBrowserType will be closed before opening the new window</param> /// <param name="maximizeWindow">If true, the new window will be maximized if not already</param> public static BrowserWindow Open(string url, string webBrowserType, bool closeAllOtherBrowserWindows = true, bool maximizeWindow = true) { WebBrowserType browserType = ParseBrowserType(webBrowserType); InitializeAgent(browserType); if (closeAllOtherBrowserWindows) { Agent.CloseAllBrowserWindows(); } IWebBrowserWindow _browser = Agent.OpenNewBrowser(url); if (maximizeWindow) { _browser.MaximizeBrowserWindow(); } //hackhack: below waitForDocumentReadyState occasionally raise exception, so catch it then retry to open the browser try { _browser.WaitForDocumentReadyState(); } catch (WebOperationFailedException) { Agent.CloseAllBrowserWindows(); _browser = Agent.OpenNewBrowser(url); _browser.WaitForDocumentReadyState(); } //Logger.Instance.LogInfo("Opening a browser window, url: " + url + ", browser type: " + webBrowserType); //Historian.AddVisistedUrl(url); return(new BrowserWindow(_browser)); }