c# - How can I get URLs of open pages from Chrome and Firefox? -
i'm writing system tray app needs check if internal web based app open.
i can check ie using 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 open"); } else { console.writeline("app not open"); }; console.readkey(true);
however, of users using system prefer chrome or firefox.
how can same above (i.e. urls of open tabs in browser) chrome , firefox? (i'm not going bother other browsers these ones in use in our organisation.)
it's specific every browser. that's major ones:
- internet explorer - can use shdocvw (like did)
- firefox - can url using dde (source below)
- chrome - can url while enumerating child windows untill control class "chrome_omniboxview" , text using
getwindowtext
- opera - can use same thing firefox, "opera"
- safari - there no known method since uses custom drawn controls
edit: since 2014, chrome has changed , need url acessibility.
code url firefox/opera using dde (which used ndde - dde wrapper .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; } }
Comments
Post a Comment