5

I have already been here:

I know there are lots of questions already out there about this topic, BUT none of them answers it correctly. I am curious how to get the URL of all open pages in firefox, but i dont find a solution that provides working code.

This is the most rewarded solution on the internet, but it does not work for me. This code uses DDE (which used NDDE - a good DDE wrapper for .NET):

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

I dont care about if it shows the history, gets the URLs of open pages in a second Firefox window, i want to keep it simple by now. Please dont provide me code for another browser as it is always browser specific or any VB code.

L. Guthardt
  • 1,990
  • 6
  • 22
  • 44
  • Why not VB code that is almost the same as C# and if you are looking for copy and paste solution you are at the wrong place. – Jordy van Eijk Jul 11 '17 at 14:10
  • I know, it isnt my intention to get a clean copy paste solution, thats not what programming passion is about. But i am kinda new to C# so i have no idea how to handle VB to be honest. – L. Guthardt Jul 11 '17 at 14:14

1 Answers1

-2

This works even if you use Firefox > 49:

System.Windows.Automation.AutomationElement AutomationElement = System.Windows.Automation.AutomationElement.FromHandle(ptr);
System.Windows.Automation.AutomationElement Elm = AutomationElement.FindFirst(TreeScope.Descendants, new PropertyCondition(AutomationElement.ControlTypeProperty, ControlType.Document));
System.Windows.Automation.AutomationPattern[] BAutomationPattern = Elm.GetSupportedPatterns();
System.Windows.Automation.ValuePattern BValuePattern = (System.Windows.Automation.ValuePattern)Elm.GetCurrentPattern(BAutomationPattern[0]);
CurrentUrlName = BValuePattern.Current.Value.ToString();
Nae
  • 14,209
  • 7
  • 52
  • 79
Marlon Remedios
  • 57
  • 1
  • 1
  • 4