How to Get Urls of Open Pages from Chrome and Firefox

How can I get URLs of open pages from Chrome and Firefox?

It's specific for every browser. That's for the major ones:

  • Internet Explorer - You can use SHDocVw (like you did)
  • Firefox - You can get the URL using DDE (source below)
  • Chrome - You can get the URL while enumerating all the child windows untill you get to the control with class "Chrome_OmniboxView" and then get the text using GetWindowText
  • Opera - You can use the same thing as Firefox, but with "opera"
  • Safari - There is no known method since it uses custom drawn controls

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;
}
}

data:// url works on Firefox but not on Chrome?

Turns out @code was correct.

My problem was that I messed up the formatting of the data URL by using 2 slashes data://, rather than the correct format of data:

data:video/mp4;base64,AAAAIGZ0eXBpc29tAAACAG...

The above finally works on both browsers.

Firefox accepts both formats — while Chrome is more strict about that rule. A bit annoying Chrome doesn't throw any error for it.

Firefox addon: Can't use browser.tabs.create more than one time

It worked using chrome.tabs.create({ url: adresse });



Related Topics



Leave a reply



Submit