It retrieves the URL (protocol included) of any browser via either MSAA framework or UI Automation interfaces.
Testing made with the most used* browsers as of September 2023 (versions as of October 2023).
* Chrome, Edge, Firefox and Opera (market share above 1%).
It uses the WinTitle & Last Found Window mechanism, so it receives up to 4 parameters (all optional) as described in the WinExist()
docs function.
Function signature:
url := GetUrl([WinTitle, WinText, ExcludeTitle, ExcludeText])
- F1 will retrieve the URL from the active window.
- F2 will retrieve the URL of the last found window.
- F3 will retrieve the URL when the browser is not active.
#Requires AutoHotkey v2.0
F1:: {
url := GetUrl("A")
if (url) {
MsgBox(url, "Active window URL", 0x40040)
} else {
MsgBox("Couldn't retrieve an URL from the active window.", "Error", 0x40010)
}
}
F2:: {
WinExist("Mozilla Firefox")
url := GetUrl()
if (url) {
MsgBox(url, "Current URL in Firefox", 0x40040)
} else {
MsgBox("Couldn't retrieve Firefox URL.", "Error", 0x40010)
}
}
F3:: {
url := GetUrl("ahk_exe firefox.exe")
if (url) {
MsgBox(url, "Current URL in Firefox", 0x40040)
} else {
MsgBox("Couldn't retrieve Firefox URL.", "Error", 0x40010)
}
}
Files marked with an asterisk work standalone (ie, don't require a library).
- GetUrl.ahk* - Active window only
- GetUrl1.ahk* - Active window only (v1.1)
- GetUrl_Acc.ahk - Uses MSAA
- GetUrl_Acc1.ahk - Uses MSAA (v1.1)
- GetUrl_UIA.ahk - Uses UIAutomation
- GetUrl_UIA1.ahk - Uses UIAutomation (v1.1)
Rename to GetUrl.ahk
if using libraries of functions.
Links to Accessibility libraries:
- MSAA Lib (maintained by me) for AutoHotkey (v2.0/v1.1).
- UIAutomation Lib (maintained by thqby) for AutoHotkey v2.0.
- UIAutomation Lib (maintained by Descolada) for AutoHotkey v2.0 (and v1.1).
@tdalon
It was working for a couple of years at least but sadly, Google in their infinity
stupiditywisdom changed the detection for the Assistive Technology. A few years back it was like it is now... only usable with a command line switch or via the settings, then it changed to "always on" (like Chromium and all the other Chromium-based browsers).So if you want to temporarily change Chrome behavior there are two options:
chrome://accessibility
and activate it.--force-renderer-accessibility
.I don't like them so I'm gonna dig to see what I can find in the source code of chromium and how to enable it on the fly, but given how limited is my free time nowadays it might take a little bit. Is not hard, is just matter to trick Chrome into thinking there is an Assistive Technology enabled.
Another option would be roll back into the old version of the function but given that the @#$%& Google developers also removed the schema from the URL yet another check is needed (to display either
http://
orhttps://
... all in all is just Google doing thing the way they want just because. Let ,e know if you're interested in the later.