Getting active tab url from Safari

1k views Asked by At

I am trying to get the active tab url for Safari, so far I was able to get the url from all prominent browsers (IE, Firefox, Chrome, Opera) through a mix of Win32 API calls or DDE.

The issue with safari is even when I enumerate through the windows and call GetWindowText it's always null.

Any solutions out there? thanks!

1

There are 1 answers

1
Lite On
public static string getChromeURL() {
  uint MAX_PATH=255;
  IntPtr hChrome, hAddressBox;

  hChrome=GetForegroundWindow();
  hAddressBox = FindWindowEx(hChrome, IntPtr.Zero,
            "Chrome_AutocompleteEditView", IntPtr.Zero);

  StringBuilder sb = new StringBuilder(256);
  SendMessage(hAddressBox, WM_GETTEXT, (IntPtr)MAX_PATH, sb);

  string s = sb.ToString().Trim(new Char[] { ' ', '\0', '\n' });
  return s;
}