Get URL from browser to C# application

Viewed 29527

How can I get the url from a running instance of Chrome or Opera using C# .NET windows form app? Thanks!

7 Answers

I just use something like this usually:

//as soon as you open the browser: browserHandle = GetForegroundWindow();

SetFocus(browserHandle);
// send ctrl-d to get in address bar
SendKeys.SendWait("%{d}");
// send ctrl- to copy
SendKeys.SendWait("%{c}");
// then paste it where you want it

You need a DLL Import:

 [DllImport("user32.dll")]
        private static extern IntPtr GetForegroundWindow();
Related