c# - get url from chrome web browser -


i trying url chrome web browser, version 33 - using c#. have looked at, , tried, different suggestions here on - far no luck.

things have tried: automationelement -> getting current tab's url google chrome using c# "address , search bar" element can't found use of automation in 33 version of chrome web browser. tried using treewalker , these elements found:

horizontal scroll bar

back small amount

forward small amount

vertical scroll bar

back small amount

forward small amount

"title of web page..."

system menu bar

system

minimize

restore

close

ndde -> retrieve current url c# windows forms application

ndde.client.ddeclient dde = new ndde.client.ddeclient("chrome", "www_getwindowinfo"); dde.connect();  ndde.client.ddeclient dde = new ndde.client.ddeclient("chrome", "chrome_omniboxview"); dde.connect(); 

neither works... can't connect.

findwindowex ->

 [dllimport("user32.dll", setlasterror = true)] public static extern intptr findwindowex(intptr parenthandle, intptr childafter, string classname, string windowtitle);  public string getchromeurl(process process) {     intptr handle = intptr.zero;     process[] procschrome = process.getprocessesbyname("chrome");     foreach (process chrome in procschrome)     {         // chrome process must have window         if (chrome.mainwindowhandle == intptr.zero)         {             continue;         } else          {             handle = chrome.mainwindowhandle;             break;         }     }      intptr urlhandle = findwindowex(handle, intptr.zero, null, "address , search bar");     if (urlhandle != intptr.zero)     {         console.writeline("yes!");     }     return ""; } 

doesn't work either...

how far got

so have used ui spy , inspect name of omnibox in chrome 33. in ui spy can't found @ all, in inspect find "address , search bar", has url value after... question how hold of url info?

any idea?

not sure why automation route didn't work in chrome 33, automationelement link; implemented in chrome 35 , work fine. sure use first implementation supposedly takes 350ms find url. also, found using treescope.subtree instead of treescope.descendants seems work little faster, though haven't performed timed tests or anything.


Comments

  1. public static string GetActiveTabUrl()
    {
    string ret = "";
    // there are always multiple chrome processes, so we have to loop through all of them to find the
    // process with a Window Handle and an automation element of name "Address and search bar"
    Process[] procsChrome = Process.GetProcessesByName("chrome");
    foreach (Process proc in procsChrome)
    {
    // the chrome process must have a window
    if (proc.MainWindowHandle == IntPtr.Zero)
    continue;

    // to find the tabs we first need to locate something reliable - the 'New Tab' button
    AutomationElement root = AutomationElement.FromHandle(proc.MainWindowHandle);
    var SearchBar = root.FindFirst(TreeScope.Descendants,
    new PropertyCondition(AutomationElement.NameProperty, "Address and search bar"));
    if (SearchBar != null)
    return (string)SearchBar.GetCurrentPropertyValue(ValuePatternIdentifiers.ValueProperty);
    }

    return ret;
    }

    ReplyDelete

Post a Comment

Popular posts from this blog

css - Text drops down with smaller window -

php - Boolean search on database with 5 million rows, very slow -

c# - DetailsView in ASP.Net - How to add another column on the side/add a control in each row? -