title: Getting the active url of browser in C# windows form application
body: <p>I have created a window form application.
  This App get the active url of browser and save this into the text file.
  And this works fine in <strong>chrome</strong> &amp; <strong>IE</strong>.</p>
  
  <p>But when i use <strong>firefox</strong>, this will not work. This code fails to get the active url of <strong>firefox</strong> browser.</p>
  
  <p>I don't know why this happening.  </p>
  
  <p>I am using the following code to find the URL</p>
  
  <pre><code> public string GetBrowsedUrl()
          {
  
              IntPtr hwnd = APIFuncs.getforegroundWindow();
              Int32 pid = APIFuncs.GetWindowProcessID(hwnd);
              Process process = Process.GetProcessById(pid);
              string appId = proc.Id.ToString();
              string appName = proc.ProcessName;
              string appltitle = APIFuncs.ActiveApplTitle().Trim().Replace("\0", "");
              if (process == null)
                  throw new ArgumentNullException("process");
  
              if (process.MainWindowHandle == IntPtr.Zero)
                  return null;
  
              AutomationElement element = AutomationElement.FromHandle(process.MainWindowHandle);
              if (element == null)
                  return null;
  
              AutomationElement edit = element.FindFirst(TreeScope.Descendants, new PropertyCondition(AutomationElement.ControlTypeProperty, ControlType.Edit));
  
  
              string result = ((ValuePattern)edit.GetCurrentPattern(ValuePattern.Pattern)).Current.Value as string;
              return result;
          }
  </code></pre>