locked
How can I get URLs of open pages from Chrome and Firefox? RRS feed

  • Question

  • Hi All,

    Am trying to read through URL opened in all tabs in all browser,I Am done with IE,But in chrome am finding it difficult to get URL's Opened in all tabs, 

    http://social.msdn.microsoft.com/Forums/en-US/vbgeneral/thread/ca257f22-115e-43f2-a28d-c806c81061b7

    Above link i referred but it is not giving All the URL's in chrome

    http://stackoverflow.com/questions/7814027/how-can-i-get-urls-of-open-pages-from-chrome-and-firefox

    Above link also only suggesting wat to do does't explains how to do..:(

    Any Suggestion would be of great help.

    Thanks


    Arjun

    Thursday, April 25, 2013 11:34 AM

Answers

  • Hi ArjunShrivatsa,

      Welcome to MSDN Forum Support.

      Verify the link again, this reply is your answer as I think.

      

    For chrome, some windows API will get you the url, the code i provide below will only get you the current tab url but to get all url of all open tab, you have to use EnumWindows API with delegate. Try google for that.

    For Firefox, this is very difficult to do with windows API but there is dynamic data exchange (NDde) for .net that can get you the current firefox url. The library can be download from http://ndde.codeplex.com/ and add reference to NDde.dll 

     

    By the way, if you like to go deep into IE tab, you can try Accessibility class in .net, where you can control IE tabs. Sample code here http://social.msdn.microsoft.com/Forums/en-US/ieextensiondevelopment/thread/03a8c835-e9e4-405b-8345-6c3d36bc8941

    Chrome and Firefox code:

     
    using NDde.Client; //import the NDde library for firefox
    using System.Runtime.InteropServices;
    
    //For Chrome
    private const int WM_GETTEXTLENGTH = 0Xe;
    private const int WM_GETTEXT = 0Xd;
    
    [DllImport("user32.dll")]
    private extern static int SendMessage(IntPtr hWnd, uint Msg, int wParam, int lParam);
    [DllImport("user32.dll")]
    private extern static int SendMessage(IntPtr hWnd, uint Msg, int wParam, StringBuilder lParam);
    [DllImport("user32.dll", SetLastError = true)]
    private extern static IntPtr FindWindowEx(IntPtr parentHandle, IntPtr childAfter, string className, string windowTitle);
    
    public static string getChromeUrl(IntPtr winHandle)
    {
    	string browserUrl = null;
    	IntPtr urlHandle = FindWindowEx(winHandle, IntPtr.Zero, "Chrome_AutocompleteEditView", null);
    	const int nChars = 256;
    	StringBuilder Buff = new StringBuilder(nChars);
    	int length = SendMessage(urlHandle, WM_GETTEXTLENGTH, 0, 0);
    	if (length > 0)
    	{
    		SendMessage(urlHandle, WM_GETTEXT, nChars, Buff);
    		browserUrl = Buff.ToString();
    
    		return browserUrl;
    	}
    	else
    	{
    		return browserUrl;
    	}
    
    }
    
    public static Intptr GetChromeHandle()
    {
     IntPtr ChromeHandle = default(IntPtr);
     Process[] Allpro = Process.GetProcesses();
     foreach (Process pro in Allpro)
     {
      if (pro.ProcessName == "chrome")
      {
      ChromeHandle = pro.MainWindowHandle;
      break;
      }
     }
    return ChromeHandle;
    }
    
    //USAGE FOR CHROME
     private IntPtr CHandle = GetChromeHandle();
     if (! CHandle,Equals(Intptr.Zero))
     {
     string url = getChromeUrl(CHandle);
     }
    
    //=========FIREFOX======================
    //For firefox ; Download the library from http://ndde.codeplex.com/ 
    Public Shared Function GetFirefoxUrl() As string;
    	DdeClient dde = new DdeClient("Firefox", "WWW_GetWindowInfo");
    	dde.Connect();
    	string url = dde.Request("URL", int.MaxValue);
    	dde.Disconnect();
    	return url;
    

      Sincerely,

      Jason Wang


    Jason Wang [MSFT]
    MSDN Community Support | Feedback to us

    Monday, April 29, 2013 6:49 AM

All replies

  • Please check the following url

    http://stackoverflow.com/questions/13307946/get-the-urls-of-opened-tabs-in-browser


    With Thanks and Regards
    Sambath Raj.C
    click "Proposed As Answer by" if this post solves your problem or "Vote As Helpful" if a post has been useful to you
    Happy Programming!

    Thursday, April 25, 2013 11:59 AM
  • The below links give you code for the 3 browsers IE, firefox and Chrome.

    http://social.msdn.microsoft.com/Forums/en-US/vbgeneral/thread/ca257f22-115e-43f2-a28d-c806c81061b7/

    But you have to translate it from VB to C#...


    Ali Hamdar (alihamdar.com - www.ids.com.lb)

    Thursday, April 25, 2013 12:03 PM
  • Checked with that URL too but it of no use..

    THanks


    Arjun

    Friday, April 26, 2013 11:20 AM
  • Hi ArjunShrivatsa,

      Welcome to MSDN Forum Support.

      Verify the link again, this reply is your answer as I think.

      

    For chrome, some windows API will get you the url, the code i provide below will only get you the current tab url but to get all url of all open tab, you have to use EnumWindows API with delegate. Try google for that.

    For Firefox, this is very difficult to do with windows API but there is dynamic data exchange (NDde) for .net that can get you the current firefox url. The library can be download from http://ndde.codeplex.com/ and add reference to NDde.dll 

     

    By the way, if you like to go deep into IE tab, you can try Accessibility class in .net, where you can control IE tabs. Sample code here http://social.msdn.microsoft.com/Forums/en-US/ieextensiondevelopment/thread/03a8c835-e9e4-405b-8345-6c3d36bc8941

    Chrome and Firefox code:

     
    using NDde.Client; //import the NDde library for firefox
    using System.Runtime.InteropServices;
    
    //For Chrome
    private const int WM_GETTEXTLENGTH = 0Xe;
    private const int WM_GETTEXT = 0Xd;
    
    [DllImport("user32.dll")]
    private extern static int SendMessage(IntPtr hWnd, uint Msg, int wParam, int lParam);
    [DllImport("user32.dll")]
    private extern static int SendMessage(IntPtr hWnd, uint Msg, int wParam, StringBuilder lParam);
    [DllImport("user32.dll", SetLastError = true)]
    private extern static IntPtr FindWindowEx(IntPtr parentHandle, IntPtr childAfter, string className, string windowTitle);
    
    public static string getChromeUrl(IntPtr winHandle)
    {
    	string browserUrl = null;
    	IntPtr urlHandle = FindWindowEx(winHandle, IntPtr.Zero, "Chrome_AutocompleteEditView", null);
    	const int nChars = 256;
    	StringBuilder Buff = new StringBuilder(nChars);
    	int length = SendMessage(urlHandle, WM_GETTEXTLENGTH, 0, 0);
    	if (length > 0)
    	{
    		SendMessage(urlHandle, WM_GETTEXT, nChars, Buff);
    		browserUrl = Buff.ToString();
    
    		return browserUrl;
    	}
    	else
    	{
    		return browserUrl;
    	}
    
    }
    
    public static Intptr GetChromeHandle()
    {
     IntPtr ChromeHandle = default(IntPtr);
     Process[] Allpro = Process.GetProcesses();
     foreach (Process pro in Allpro)
     {
      if (pro.ProcessName == "chrome")
      {
      ChromeHandle = pro.MainWindowHandle;
      break;
      }
     }
    return ChromeHandle;
    }
    
    //USAGE FOR CHROME
     private IntPtr CHandle = GetChromeHandle();
     if (! CHandle,Equals(Intptr.Zero))
     {
     string url = getChromeUrl(CHandle);
     }
    
    //=========FIREFOX======================
    //For firefox ; Download the library from http://ndde.codeplex.com/ 
    Public Shared Function GetFirefoxUrl() As string;
    	DdeClient dde = new DdeClient("Firefox", "WWW_GetWindowInfo");
    	dde.Connect();
    	string url = dde.Request("URL", int.MaxValue);
    	dde.Disconnect();
    	return url;
    

      Sincerely,

      Jason Wang


    Jason Wang [MSFT]
    MSDN Community Support | Feedback to us

    Monday, April 29, 2013 6:49 AM
  • Chrome changed the way it handle the window and the code aboce doesn't work any more.
    Do you know the new way to read the url?

    Regards,
    Guy

    Monday, August 26, 2013 7:49 AM
  • Yes, chrome cannot work, could someone share the new code to get Chrome url ?

    Thanks.

    Tuesday, August 27, 2013 7:24 AM