I'm writing a system tray app that needs to check if an internal web based app is open.
I can check IE using the following:
SHDocVw.ShellWindows shellWindows = new SHDocVw.ShellWindows(); string filename; bool sdOpen = false; foreach (SHDocVw.InternetExplorer ie in shellWindows) { filename = Path.GetFileNameWithoutExtension(ie.FullName).ToLower(); if (filename.Equals("iexplore")) { string[] urlParts = (ie.LocationURL.ToString()).Split('/'); string website = urlParts[2]; if (website == "myApp:8080") { sdOpen = true; }; } } if (sdOpen) { Console.WriteLine("App is open"); } else { Console.WriteLine("App is not open"); }; Console.ReadKey(true);
However, some of the users using the system prefer Chrome or Firefox.
How can I do the same as above (i.e. get the urls of any open tabs in the browser) for Chrome and Firefox? (I'm not going to bother with other browsers as these are the only ones in use in our organisation.)
Press Ctrl + a on Windows/Linux or ⌘ + a on Mac to select all bookmarks. Press Ctrl + c on Windows/Linux or ⌘ + c on Mac to copy all urls (and only urls).
Click inside the field and press Ctrl + A to select all the text, then Ctrl + C to copy it. Then you can paste it into Notepad or Word to have a list of all URLs. Each one is separated with a pipe (|) symbol. Don't forget to replace your proper Home Page when done!
It's specific for every browser. That's for the major ones:
GetWindowText
EDIT: Since 2014, Chrome has changed and you need to get the URL with Acessibility.
Code to get the URL from Firefox/Opera using DDE (which used NDDE - the only good DDE wrapper for .NET):
// // usage: GetBrowserURL("opera") or GetBrowserURL("firefox") // private string GetBrowserURL(string browser) { try { DdeClient dde = new DdeClient(browser, "WWW_GetWindowInfo"); dde.Connect(); string url = dde.Request("URL", int.MaxValue); string[] text = url.Split(new string[] { "\",\"" }, StringSplitOptions.RemoveEmptyEntries); dde.Disconnect(); return text[0].Substring(1); } catch { return null; } }
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With