private void btnInstallChromeNativeMessaging_Click(object sender, EventArgs e) { try { //Install here string serverMenifestPath = Path.Combine(_localAppDataExtensionsDirectory, "com.openbots.chromeserver.message-manifest.json"); ChromeExtensionRegistryManager registryManager = new ChromeExtensionRegistryManager(); registryManager.PathValue = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "Resources", "Extensions", "kkepankimcahnjamnimeijpplgjpmdpp_main.crx"); registryManager.VersionValue = "1.5.2.1"; registryManager.NativeServerKey = serverMenifestPath; MessageBox.Show("Chrome Extension is installed, please make sure its enabled. Restart chrome browser for changes to take effect."); DialogResult = DialogResult.OK; } catch (Exception ex) { ErrorMessage = ex.Message; DialogResult = DialogResult.Cancel; } }
public static void GetUIElement(object sender, EventArgs e, DataTable nativeSearchParameters, IfrmCommandEditor editor) { ChromeExtensionRegistryManager registryManager = new ChromeExtensionRegistryManager(); bool isChromeNativeMessagingInstalled = registryManager.IsExtensionInstalled(); if (isChromeNativeMessagingInstalled) { try { User32Functions.BringChromeWindowToTop(); string webElementStr; NativeRequest.ProcessRequest("getelement", "", 60, out webElementStr); if (!string.IsNullOrEmpty(webElementStr) && webElementStr != "stopped") { if (!webElementStr.Contains("tagName")) { NativeResponse responseObject = JsonConvert.DeserializeObject <NativeResponse>(webElementStr); if (responseObject.Status == "Failed") { throw new Exception(responseObject.Result); } } WebElement webElement = JsonConvert.DeserializeObject <WebElement>(webElementStr); DataTable SearchParameters = WebElementToDataTable(webElement); if (SearchParameters != null) { nativeSearchParameters.Rows.Clear(); foreach (DataRow rw in SearchParameters.Rows) { nativeSearchParameters.ImportRow(rw); } } } } catch (Exception ex) { // Throw Error in Message Box if (ex.Message.Contains("Pipe hasn't been connected yet.")) { var result = ((Form)editor).Invoke(new Action(() => { editor.ShowMessage("Chrome Native Extension is not installed! \n Please visit: https://chrome.google.com/webstore/detail/openbots-web-automation/kkepankimcahnjamnimeijpplgjpmdpp/related", "MessageBox", DialogType.OkOnly, 10); } )); } else if (ex.Message.ToLower().Contains("arithmetic operation resulted in an overflow")) { var result = ((Form)editor).Invoke(new Action(() => { editor.ShowMessage("Chrome Native Extension stopped responding.", "MessageBox", DialogType.OkOnly, 10); } )); } else { var result = ((Form)editor).Invoke(new Action(() => { editor.ShowMessage(ex.Message, "MessageBox", DialogType.OkOnly, 10); } )); } } finally { Process process = Process.GetCurrentProcess(); User32Functions.ActivateWindow(process.MainWindowTitle); } } else { var result = ((Form)editor).Invoke(new Action(() => { editor.ShowMessage("Chrome Native Extension is not installed! \nPlease open the Extensions Manager to install Chrome Native Extension.", "MessageBox", DialogType.OkOnly, 10); } )); } }