How to get the urls of all tabs in a chrome browser

  • Thread starter Thread starter InterverseTech
  • Start date Start date
I

InterverseTech

Guest
Hey Everyone,

I am trying to create a program that can read all open tabs urls to be monitored from within a program. Ive tried other solutions involving Automation Element and it give me the name of the tab but not the URL. Here is the code I am trying to use but other suggestions would help.


List<CHROMEWINDOW> GetChromeInfo()
{
Console.WriteLine(">> Getting Chrome Tabs");

List<CHROMEWINDOW> ChromeTabs = new List<CHROMEWINDOW>();
ChromeTabs.Clear();

Process[] procsChrome = Process.GetProcessesByName("chrome");
if (procsChrome.Length <= 0)
{
Console.WriteLine(">> Chrome not running");
return null;
}
else
{

foreach (Process proc in procsChrome)
{

if (proc.MainWindowHandle == IntPtr.Zero)
{
//Console.WriteLine(">> Main Window matches IntPtr Zero");
continue;
}

AutomationElement root = AutomationElement.FromHandle(proc.MainWindowHandle);
Condition condNewTab = new PropertyCondition(AutomationElement.NameProperty, "New Tab");
AutomationElement elmNewTab = root.FindFirst(TreeScope.Descendants, condNewTab);
TreeWalker treewalker = TreeWalker.ControlViewWalker;
AutomationElement elmTabStrip = treewalker.GetParent(elmNewTab);
Condition condTabItem = new PropertyCondition(AutomationElement.ControlTypeProperty, ControlType.TabItem);
foreach (AutomationElement tabitem in elmTabStrip.FindAll(TreeScope.Children, condTabItem))
{
Console.WriteLine(">> Adding Tab - {0}", tabitem.Current.Name);
CHROMEWINDOW win = new CHROMEWINDOW(proc, tabitem.Current.Name.ToString());
ChromeTabs.Add(win);
}



}


return ChromeTabs;
}
}


Thanks for your responses in advance!


- Nathan Hastings Executive Of Interverse Software

Continue reading...
 
Back
Top