Reputation: 2206
I'm wondering if there's any way for a Windows desktop application (i.e. compiled using the Windows SDK) to get the current URL for a browser window running in another process.
Put another way, I'm wondering if there's an equivalent method in Windows to using AppleScript / Apple events in macOS:
tell application "Chrome" to get the URL of the active tab of front window
I'm working in C++ but since the underlying API is the Windows SDK, I'm open to other languages too such as C#.
I'd love a general approach that works for Chromium-based browsers like the above AppleScript example in macOS, but if need be I'll implement different methods for each web browser I want to support.
Upvotes: 0
Views: 57
Reputation: 2936
I do not think that there is any such kind of API on Windows and if there was, it would probably only work with Microsoft Edge.
This kind of functionality is usually implemented in the form of a browser extension. The browser extension has access to the current state of the browser and can communicate with other applications on the system, e.g., by opening a socket.
For example, the literature management system Zotero implements it this way. Their browser extension sends the currently viewed website to the desktop application in order to insert it into its database. Their desktop client and browser extensions are open-source, so you can go and check the details of their implementation.
Of course, the downside of this approach is that you have to tell users to trust and install your browser extension. But the upside is privacy for the user.
Upvotes: 0