Getting firefox url

I need to know the url at which the user is currently (with firefox)
I was thinking of a keylogger to track the url,
but what when the user clicks the link?
The name is not enough, I need the full URL. This is easy with IE, but not with firefox. for IE I use:

private string GetUrlFromIE() { IntPtr windowHandle = GetForegroundWindow(); IntPtr childHandle; String strUrlToReturn = ""; //IE toolbar container childHandle = FindWindowEx(windowHandle,IntPtr.Zero,"WorkerW",IntPtr.Zero); if(childHandle != IntPtr.Zero) { //get a handle to address bar childHandle = FindWindowEx(childHandle,IntPtr.Zero,"ReBarWindow32",IntPtr.Zero); if(childHandle != IntPtr.Zero) { // get a handle to combo boxes childHandle = FindWindowEx(childHandle, IntPtr.Zero, "ComboBoxEx32", IntPtr.Zero); if(childHandle != IntPtr.Zero) { // get a handle to combo box childHandle = FindWindowEx(childHandle, IntPtr.Zero, "ComboBox", IntPtr.Zero); if(childHandle != IntPtr.Zero) { //get handle to edit childHandle = FindWindowEx(childHandle, IntPtr.Zero, "Edit", IntPtr.Zero); if (childHandle != IntPtr.Zero) { strUrlToReturn = GetText(childHandle); } } } } } return strUrlToReturn; } 

any ideas?

+4
source share
2 answers

In javascript, you can access the url with

 window.location.href 
0
source

You can get the URL using the Windows IAccessible interface.

To simplify the handling of IAccess, I recommend using a managed Windows API . You must have a FireFox window handler in advance.

Here is the C # code to grab the URL from FireFox:

  private static string GetUrlFromFirefox(IntPtr windowHandle) { SystemAccessibleObject sao = SystemAccessibleObject.FromWindow(new SystemWindow(windowHandle), AccessibleObjectID.OBJID_WINDOW); var preds = new Predicate<SystemAccessibleObject>[] { s => s.RoleString == "application", s => s.RoleString == "property page", s => s.RoleString == "grouping" && s.StateString == "None", s => s.RoleString == "property page" && s.StateString == "None", s => s.RoleString == "browser", s => s.RoleString == "document" && s.Visible }; var current = sao.Children; SystemAccessibleObject child = null; foreach (var pred in preds) { child = Array.Find(current, pred); if (child != null) { current = child.Children; } } if (child != null) { return child.Value; } return string.Empty; } 

This works for FireFox 14.

+3
source

All Articles