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
Auto Create Database in Entity Framework Core
.Net Asynchronous Stream Read/Write
Why Cannot Ienumerable<Struct> Be Cast as Ienumerable<Object>
Practical Uses for the "Internal" Keyword in C#
How to Programmatically Click a Button in Wpf
Serialize Property, But Do Not Deserialize Property in JSON.Net
C# Windows Forms Application - Updating Gui from Another Thread and Class
Why Is Typedreference Behind the Scenes? It's So Fast and Safe... Almost Magical!
What Is Func, How and When Is It Used
Getting a System.Type from Type's Partial Name
MVC Web API: No 'Access-Control-Allow-Origin' Header Is Present on the Requested Resource
Converting File into Base64String and Back Again
Passing Command-Line Arguments in C#
Datetime.Tryparse Century Control C#