title: Browser and external app communication? (Chrome's current url and referrer on Windows?)
body: <p>How might an external program communicate with a browser? Hopefully this will be of some use to others: I'm listing off a number of options I've seen or tried while unsuccessfully getting this to work. If you know of others, please post them.</p>
  
  <ul>
  <li>If Mac, use AppleScript (info/solution at <a href="https://stackoverflow.com/questions/263741/using-applescript-to-grab-the-url-from-the-frontmost-window-in-web-browsers-the">q.263741</a>, try <a href="http://www.google.com/search?q=%22set+%2A+to+GetWindowInfo%22" rel="nofollow noreferrer">this search</a>)</li>
  <li>Use or create an extension for Firefox (<a href="http://www.iopus.com/imacros/firefox/" rel="nofollow noreferrer">iMacros</a>?, <a href="https://stackoverflow.com/questions/410411/get-current-page-url-from-a-firefox-sidebar-extension">q.410411</a>), Chrome (?)</li>
  <li>Use a <a href="http://msdn.microsoft.com/en-us/library/2te2y1x6.aspx" rel="nofollow noreferrer">WebBrowser Control</a> to host an IE instance (some tips at <a href="https://stackoverflow.com/questions/1143187/get-current-url-from-browser">q.1143187</a>)</li>
  <li>If you own the site, this can be done with a background ajax script</li>
  </ul>
  
  <hr>
  
  <p>My question: how can I get the current foreground browser's (Chrome, specifcally) URL and referrer from an external windows app, without modifying the browser?</p>
  
  <p>I've tried using User32's GetWindowText, which grabs the title (using jNative for Java). This often lets me guess the server. It may be possible to write a local proxy that will map titles to URLs, but this is much work. I've written a FireFox extension to rig the window title with this information, but it became outdated, and I need this for Chrome now anyway. I'd prefer not to add junk to the browser, unless broadly useful. Perhaps I could file a feature request for an applescript-like api for chrome on windows. <a href="http://www.autohotkey.com/forum/topic8976.html" rel="nofollow noreferrer">AHK Window Info 1.7</a> manages to grab the URL (but not referrer) under visible/hidden text, but I have no idea how to port the code it uses.</p>
  
  <p>(Some info for FF/C# at <a href="https://stackoverflow.com/questions/990409/how-to-retreive-url-from-browser-using-c">q.990409</a> &amp; <a href="http://social.msdn.microsoft.com/forums/en/csharpgeneral/thread/c60b1699-9fd7-408d-a395-110c1cd4f297" rel="nofollow noreferrer">here</a>, some IE info at <a href="https://stackoverflow.com/questions/823755/get-url-from-web-browser">q.823755</a> (redirects to <a href="https://stackoverflow.com/questions/352236/reading-from-a-text-field-in-another-applications-window">q.352236</a>). No info at <a href="https://stackoverflow.com/questions/1107978/how-can-i-get-the-current-location-url-of-mozilla-browser-using-c">q.1107978</a>.
  Ignore this: <em>Related questions: How can I control firefox with a macro? How can I get browser information? How can I get current browser URL? How can I get chrome's current URL from an external app?</em>)</p>
  
  <p>Ideas, code samples, pointers to potentially relevant questions, and answers to my specific question are all appreciated.</p>