10

Up to Chrome V27 you could enumerate Chrome child window controls to get to the edit field and read the string value from there to get the current opened URL.

Unfortunately Chrome 28 has switched to the new rendering Engine (Blink) and does not use Windows controls anymore besides the main window (Chrome_WidgetWin_1) and the web page tab (Chrome_RenderWidgetHostHWND).

I would be grateful if someone could point to an alternative method of getting the currently opened Chrome URL from another (Win32) application.

Casady
  • 1,426
  • 3
  • 19
  • 39
  • I consider this change to be an excellent move security-wise. Being able to break it without a Debugger could be considered a bug in Chrome 28 (and thus be subject to change) – Eugen Rieck May 30 '13 at 17:03
  • 3
    @Eugen There's no security at all in making url reading a little more awkward. – David Heffernan May 30 '13 at 17:15
  • 2
    For my taste, making it hard to read from an external application is a good idea. – Eugen Rieck May 30 '13 at 17:33
  • 5
    @Eugen It's not an external app. Processes running on the same machine can pretty much see everything in other processes on that machine. If you think that v28 is more secure for that reason, you are deluding yourself. – David Heffernan May 30 '13 at 17:41
  • Very similar discussions can be found here. [enter link description here][1] [1]: http://stackoverflow.com/questions/18413751/how-to-get-google-chrome-web-browser-active-tabs-url-vb6 – vengy Sep 21 '13 at 01:52
  • Is there a purpose for this other than spyware? – Boann Sep 24 '13 at 15:33
  • 1
    any bookmark collecting or document management software needs this. – Casady Sep 24 '13 at 21:34
  • @Casady such software might as well be implemented as a Chrome extension (plugin). This would allow users to decide if they allow external access or not. – mjn Sep 14 '14 at 14:09

2 Answers2

12

Chrome supports the Windows accessibility APIs, so you can use those to extract information both from the chrome - including the broswer bar - and also from web pages. Think of this API as a more abstract version of enumerating window controls.

Check out the Inspect Objects tool to explore what information you can get access to - it does look as though the address bar and contents are available.

You can get the same information in C# using the AutomationElement set of classes:

  • use AutomationElement windowEl = AutomationElement.FromHandle(new IntPtr(hwnd)); as a starting point if you know the HWND of the tree
  • then try AutomationElement editEl = AutomationElement.FindFirst(TreeScope.Descendants, new PropertyCondition(AutomationElement.ControlTypeProperty, ControlType.Edit)) to find the first element that has ControlType of Edit. FindFirst does a depth-first search of the tree, which looks like it will work in this case; can use the TreeWalker classes if you want to walk step-by-step yourself.
  • 'cast' the found element to a ValuePattern using: ValuePattern vp = (ValuePattern) editEl.GetCurrentPattern(ValuePattern.Pattern);
  • Finally, use string str = vp.Current.Value; to get the value of the edit.
Jon Limjap
  • 94,284
  • 15
  • 101
  • 152
BrendanMcK
  • 14,252
  • 45
  • 54
4

AFAIK you could do this by creating a chrome extension which then communicates with the application using WebSockets.

There's even a Delphi implementation of the Web Socket protocol(with examples) -> DelphiWs

More relevant info here. That should get you started.

Peter
  • 2,977
  • 1
  • 17
  • 29
  • I have already an extension that communicates over tcp/ip. But the problem is that the communication is chrome -> myapp and not myapp -> chrome. So the user can click a button in the chrome extension and the URL is send to my application, but it's not possible to click a button in my app and get the URL from chrome since V28. As far as I understand using web sockets is not possible in chrome extension outside of the dev channel chrome version. – Casady May 30 '13 at 19:54