Get URL from Chrome web browser

I am trying to get url from chromed web browser, version 33 - using C #. I looked and tried different suggestions here on SO - but so far no luck.

Things I tried: AutomationElement -> Getting the URL of the current tab from Google Chrome using C # The "Addresses and Search Bar" element cannot be found using Automation in version 33 of the Chrome browser. I also tried using TreeWalker, and where only those elements were found:

Horizontal scroll bar

Back a little

Forward a small amount

Vertical scroll bar

Back a little

Forward a small amount

"Webpage Name ..."

System menu bar

System

Minimization

Recovery

Close

NDde → URL- Windows Forms

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();

... .

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)
    {
        // the chrome process must have a window
        if (chrome.MainWindowHandle == IntPtr.Zero)
        {
            continue;
        } else 
        {
            handle = chrome.MainWindowHandle;
            break;
        }
    }

    IntPtr urlHandle = FindWindowEx(handle, IntPtr.Zero, null, "Address and search bar");
    if (urlHandle != IntPtr.Zero)
    {
        Console.WriteLine("yes!");
    }
    return "";
}

...

, UI Spy , omnibox Chrome 33. UI- , " ", url, ... , url?

?

+4
2

, Chrome 33 AutomationElement; Chrome 35, . , , , 350 , URL-. , , TreeScope.Subtree TreeScope.Descendants, , , - .

+1

API?

getURL - chrome.runtime.getURL()

: API

-1

Source: https://habr.com/ru/post/1531292/


All Articles