Hello
It seems it does not work properly if I have many tabs opened. It does not return the url of the current active tab.
Get the URL of the current (active) browser tab
Re: Get the URL of the current (active) browser tab
Thanks for the code atnbueno. I have a simple implementation to get the chrome URL. What do you think?
Code: Select all
GetChromeURL()
{
WinGetClass, ActWinClass, A
if (ActWinClass = "Chrome_WidgetWin_1")
{
tempclip1:=clipboard
sleep,12 ;8eg3w
blockinput, on
send, !{d}
sleep,12 ;8eg3w
send, ^{c}
sleep,12 ;8eg3w
tempclip2:=clipboard
sleep,12 ;8eg3w
clipboard:=tempclip1
sleep,12 ;8eg3w
blockinput, off
return tempclip2
}
}
-
- Posts: 5
- Joined: 17 Feb 2017, 13:07
Re: Get the URL of the current (active) browser tab
Yes, sadly it grabs a specific tab/window and insists on returning that one instead of the currently active tab/window URL or last used.Thierry wrote:Hello
It seems it does not work properly if I have many tabs opened. It does not return the url of the current active tab.
Re: Get the URL of the current (active) browser tab
For PaleMoon 27.2.1 (32-bit) on Win7-x64, 64-bit AHK, I get ("The URL couldn't be determined"(MozillaWindowClass")).
Chrome works, reports (Chrome_WinWidget_1).
Firefox is the fastest of the one's I've tried so far, 437ms.
Interestingly, when Thunderbird is open, if you select a message with the mouse, it gives you a URL for the message and also reports MozillaWindowClass, which I guess is no surprise.
Thanks for the script!
Chrome works, reports (Chrome_WinWidget_1).
Firefox is the fastest of the one's I've tried so far, 437ms.
Interestingly, when Thunderbird is open, if you select a message with the mouse, it gives you a URL for the message and also reports MozillaWindowClass, which I guess is no surprise.
Thanks for the script!
Re: Get the URL of the current (active) browser tab
Please excuse my ignorance in this type of script, this is seeing for the first time, how can I get the data of this script in an external program, developed in vb.net, I want to capture the active url of this script. thank you.
Re: Get the URL of the current (active) browser tab
(Sorry for not seeing your message before)Thierry wrote:Hello
It seems it does not work properly if I have many tabs opened. It does not return the url of the current active tab.
That shouldn't happen Which browser/version are you using? Are you using the script from the first page unmodified?
Excuse my ignorance in vb.net but this script uses the Microsoft Active Accessibility (MSAA) API. You can find links to the relevant Microsoft documentation in https://autohotkey.com/board/topic/7730 ... -09272012/ If you are able to understand it, you will have no problem in replicating the functionality.Cardoso wrote:Please excuse my ignorance in this type of script, this is seeing for the first time, how can I get the data of this script in an external program, developed in vb.net, I want to capture the active url of this script. thank you.
Regards,
Antonio
-
- Posts: 74
- Joined: 18 May 2017, 10:56
Re: Get the URL of the current (active) browser tab
Thanks atnbueno, great script. There is a bug and I don't know how to fix the problem. If I opened two Chrome windows (each with different tabs), the script works well but once I add a new blank tab and press the ^+!u then the script will return the previous active tab URL and after that it get stuck on that URL and couldn't identify the current tab URL anymore. Can this problem be solved?
I am using the script from the first page unmodified. Chrome browser version 58.0.3029.110 (64-bit)
I am using the script from the first page unmodified. Chrome browser version 58.0.3029.110 (64-bit)
Re: Get the URL of the current (active) browser tab
Hello atnbueno,
I'm looking for a way to get (additionally) the title of the page shown in the current (active) browser tab - in my case for Firefox. Any hints are highly appreciated!
Many thanks and greetings
hotkeyguy
I'm looking for a way to get (additionally) the title of the page shown in the current (active) browser tab - in my case for Firefox. Any hints are highly appreciated!
Many thanks and greetings
hotkeyguy
Re: Get the URL of the current (active) browser tab
Hi
The problem with this lib is that its very slow once i have many (like 200) tabs opened.
Retrieving url time goes down to 1541ms on Chrome.
When i open fresh Edge browser with just one tab, the retrieval time is about 100ms.
So is there something that can be done to speed up url retrieval?
The problem with this lib is that its very slow once i have many (like 200) tabs opened.
Retrieving url time goes down to 1541ms on Chrome.
When i open fresh Edge browser with just one tab, the retrieval time is about 100ms.
So is there something that can be done to speed up url retrieval?
Re: Get the URL of the current (active) browser tab
I think this worked for some time. But, now, with Firefox v56.0.2, both Modern and Legacy functions return an empty string. Could someone one of the browsers guru here investigate this code ?Danny wrote:If anyone had this script fail with the Firefox version 50 release, here was my solution:
Just put Mozilla with the Legacy Browsers, so it uses DDE instead of ACC.
Many thanks.
Author of freeware Quick Access Popup, the powerful Windows folders, apps and documents launcher!
Now working on Quick Clipboard Editor
The Automator's Courses on AutoHotkey
Now working on Quick Clipboard Editor
The Automator's Courses on AutoHotkey
Re: Get the URL of the current (active) browser tab
- This quick fix is working for me.
- If your locale isn't English, you may like to try the numeric version of vAccPath that is currently commented out.
- It requires the Acc library.
- It may be that it can be simplified, I haven't looked at it in a long time.
- If the 'http://' bit is hidden, it assumes 'http://'.
- If your locale isn't English, you may like to try the numeric version of vAccPath that is currently commented out.
- It requires the Acc library.
- It may be that it can be simplified, I haven't looked at it in a long time.
- If the 'http://' bit is hidden, it assumes 'http://'.
Code: Select all
;[Acc functions]
;Acc library (MSAA) and AccViewer download links - AutoHotkey Community
;https://autohotkey.com/boards/viewtopic.php?f=6&t=26201
q:: ;mozilla firefox - get url
WinGet, hWnd, ID, A
vUrl := JEE_FirefoxGetUrl(hWnd)
MsgBox, % vUrl
return
JEE_FirefoxGetUrl(hWnd, vOpt:="")
{
Loop, 10
{
vIndex := A_Index
vAccPath := "application.tool_bar3.combo_box1.editable_text"
;vAccPath := "4.25.3.2"
if InStr(vOpt, "p") ;(pop-up window)
vAccPath := "application.tool_bar1.combo_box1.editable_text"
oAcc := Acc_Get("Object", vAccPath, 0, "ahk_id " hWnd)
if !ErrorLevel
break
Sleep, 100
}
if (vIndex = 10)
return
vUrl := ""
try vUrl := oAcc.accValue(0)
if !(vUrl = "") && !InStr(vUrl, "://")
vUrl := "http://" vUrl
return vUrl
}
homepage | tutorials | wish list | fun threads | donate
WARNING: copy your posts/messages before hitting Submit as you may lose them due to CAPTCHA
WARNING: copy your posts/messages before hitting Submit as you may lose them due to CAPTCHA
Re: Get the URL of the current (active) browser tab
Thanks jeeswg. I'll look at it soon.
Just FYI, yes I'm my locale is not English (it is French-Canadian) but both functions work well with IE (legacy) or Chrome (modern). The issue is just with Firefox, AKAIK.
Just FYI, yes I'm my locale is not English (it is French-Canadian) but both functions work well with IE (legacy) or Chrome (modern). The issue is just with Firefox, AKAIK.
Author of freeware Quick Access Popup, the powerful Windows folders, apps and documents launcher!
Now working on Quick Clipboard Editor
The Automator's Courses on AutoHotkey
Now working on Quick Clipboard Editor
The Automator's Courses on AutoHotkey
Re: Get the URL of the current (active) browser tab
@jeeswg: I tried to fit your code in mine but I think our codes are based on the same source in this thread. There has been some variations/branched from the OP code in this thread and I'l a little lost ;-)
But, using the GetAddressBar(accObj, accPath:="") function as found on page 4 https://autohotkey.com/boards/viewtopic ... 48#p109548 (second piece of code in it), it made my script work again with Firefox 56.
But, using the GetAddressBar(accObj, accPath:="") function as found on page 4 https://autohotkey.com/boards/viewtopic ... 48#p109548 (second piece of code in it), it made my script work again with Firefox 56.
Author of freeware Quick Access Popup, the powerful Windows folders, apps and documents launcher!
Now working on Quick Clipboard Editor
The Automator's Courses on AutoHotkey
Now working on Quick Clipboard Editor
The Automator's Courses on AutoHotkey
Re: Get the URL of the current (active) browser tab
Is there a way for it to just check every 10 seconds and write to a file the active url instead of me needing to do it with a hotkey?
I know how to write to a file just need to know how to get it to check without hotkey, i tried removing the hotkey but then it doesnt work
I know how to write to a file just need to know how to get it to check without hotkey, i tried removing the hotkey but then it doesnt work
Re: Get the URL of the current (active) browser tab
This thread is about getting the URL out of the current browser. Repeating it every 10 seconds is another topic. I suggest you start an new topic for this. It could be helpful for users having anything else to execute repeatedly.Bunny the Dummy wrote:Is there a way for it to just check every 10 seconds and write to a file the active url instead of me needing to do it with a hotkey?
I know how to write to a file just need to know how to get it to check without hotkey, i tried removing the hotkey but then it doesnt work
Author of freeware Quick Access Popup, the powerful Windows folders, apps and documents launcher!
Now working on Quick Clipboard Editor
The Automator's Courses on AutoHotkey
Now working on Quick Clipboard Editor
The Automator's Courses on AutoHotkey
Re: Get the URL of the current (active) browser tab
If this can help, here is my full script for getting the URL and getting the web page title. Most of the code for getting the URL comes from this thread but code formatting and variables naming were adapted to my own style.
Tested with IE 11, Chrome and Firefox 57 and Edge 40. Alt-Q to test it.
Tested with IE 11, Chrome and Firefox 57 and Edge 40. Alt-Q to test it.
Code: Select all
#SingleInstance force ; Skips the dialog box and replaces the old instance automatically
g_strModernBrowsers := "ApplicationFrameWindow,Chrome_WidgetWin_0,Chrome_WidgetWin_1,Maxthon3Cls_MainFrm,Slimjet_WidgetWin_1,MozillaWindowClass"
g_strLegacyBrowsers := "IEFrame,OperaWindowClass"
;------------------------------------------------------------
!q::
;------------------------------------------------------------
strURL := ""
WinGetClass, strClass, A
if InStr(g_strModernBrowsers, strClass)
strURL := GetCurrentUrlAcc(strClass)
else if InStr(g_strLegacyBrowsers, strClass)
strURL := GetCurrentUrlDDE(strClass) ; empty string if DDE not supported (or not a browser)
if StrLen(strURL)
MsgBox, % "Class: " . strClass
. "`nURL: " . strURL
. "`nTitle: " . GetWebPageTitle(strURL)
else
MsgBox, Current window is not a browser
return
;------------------------------------------------------------
;------------------------------------------------------------
GetCurrentUrlDDE(strClass)
; "GetCurrentUrlDDE" adapted from DDE code by Sean, (AHK_L version by maraskan_user) (via Joe Glines)
; Found at http://autohotkey.com/board/topic/17633-/?p=434518
;------------------------------------------------------------
{
WinGet, strServer, ProcessName, % "ahk_class " . strClass
StringTrimRight, strServer, strServer, 4
intCodePage := (A_IsUnicode ? 0x04B0 : 0x03EC) ; 0x04B0 = CP_WINUNICODE, 0x03EC = CP_WINANSI
DllCall("DdeInitialize", "UPtrP", idInst, "Uint", 0, "Uint", 0, "Uint", 0)
hServer := DllCall("DdeCreateStringHandle", "UPtr", idInst, "Str", strServer, "int", intCodePage)
hTopic := DllCall("DdeCreateStringHandle", "UPtr", idInst, "Str", "WWW_GetWindowInfo", "int", intCodePage)
hItem := DllCall("DdeCreateStringHandle", "UPtr", idInst, "Str", "0xFFFFFFFF", "int", intCodePage)
hConv := DllCall("DdeConnect", "UPtr", idInst, "UPtr", hServer, "UPtr", hTopic, "Uint", 0)
hData := DllCall("DdeClientTransaction", "Uint", 0, "Uint", 0, "UPtr", hConv, "UPtr", hItem, "UInt", 1, "Uint", 0x20B0, "Uint", 10000, "UPtrP", nResult) ; 0x20B0 = XTYP_REQUEST, 10000 = 10s timeout
sData := DllCall("DdeAccessData", "Uint", hData, "Uint", 0, "Str")
DllCall("DdeFreeStringHandle", "UPtr", idInst, "UPtr", hServer)
DllCall("DdeFreeStringHandle", "UPtr", idInst, "UPtr", hTopic)
DllCall("DdeFreeStringHandle", "UPtr", idInst, "UPtr", hItem)
DllCall("DdeUnaccessData", "UPtr", hData)
DllCall("DdeFreeDataHandle", "UPtr", hData)
DllCall("DdeDisconnect", "UPtr", hConv)
DllCall("DdeUninitialize", "UPtr", idInst)
csvWindowInfo := StrGet(&sData, "CP0")
StringSplit, strWindowInfo, csvWindowInfo, `" ;"; comment to avoid a syntax highlighting issue in autohotkey.com/boards
Return strWindowInfo2
}
;------------------------------------------------------------
;------------------------------------------------------------
GetCurrentUrlAcc(strClass)
; Found at https://autohotkey.com/boards/viewtopic.php?f=6&t=3702&start=60
;------------------------------------------------------------
{
; static or global?
global nWindow
global accAddressBar
If (nWindow != WinExist("ahk_class " strClass)) ; reuses accAddressBar if it's the same window
{
nWindow := WinExist("ahk_class " strClass)
accAddressBar := GetAddressBar(GetCurrentUrlAccObjectFromWindow(nWindow))
}
Try sURL := accAddressBar.accValue(0)
If (sURL == "")
{
WinGet, nWindows, List, % "ahk_class " strClass ; In case of a nested browser window as in the old CoolNovo (TO DO: check if still needed)
If (nWindows > 1)
{
accAddressBar := GetAddressBar(GetCurrentUrlAccObjectFromWindow(nWindows2))
Try sURL := accAddressBar.accValue(0)
}
}
If ((sURL != "") and (SubStr(sURL, 1, 4) != "http")) ; Modern browsers omit "http://"
sURL := "http://" . sURL
If (sURL == "")
nWindow := -1 ; Don't remember the window if there is no URL
Return sURL
}
;------------------------------------------------------------
;------------------------------------------------------------
GetAddressBar(accObj, accPath:="")
; "GetAddressBar" based in code by stealzy
; Found at https://autohotkey.com/boards/viewtopic.php?p=109548#p109548
; IsUrl in this functions above replaced by my own code LocationIsHttp
;------------------------------------------------------------
{
n := 0
Try If ((accObj.accRole(0) == 42) and StrLen(accObj.accValue(0)) and LocationIsHttp(accObj.accValue(0)))
Return accObj
Try If ((accObj.accRole(0) == 42) and StrLen(accObj.accValue(0)) and LocationIsHttp("http://" . accObj.accValue(0))) ; Modern browsers omit "http://"
Return accObj
For nChild, accChild in GetCurrentUrlAccChildren(accObj)
{
n++
currentPath := accPath . n . "."
If IsObject(accAddressBar := GetAddressBar(accChild, currentPath))
Return accAddressBar
}
}
;------------------------------------------------------------
;------------------------------------------------------------
GetCurrentUrlAccInit()
; Part of the Acc.ahk Standard Library by Sean (updated by jethrow) (via Joe Glines)
; Found at http://autohotkey.com/board/topic/77303-/?p=491516
;------------------------------------------------------------
{
static h
If Not h
h := DllCall("LoadLibrary", "Str", "oleacc", "Ptr")
}
;------------------------------------------------------------
;------------------------------------------------------------
GetCurrentUrlAccObjectFromWindow(hWnd, idObject = 0)
; Part of the Acc.ahk Standard Library by Sean (updated by jethrow) (via Joe Glines)
; Found at http://autohotkey.com/board/topic/77303-/?p=491516
;------------------------------------------------------------
{
GetCurrentUrlAccInit()
If DllCall("oleacc\AccessibleObjectFromWindow", "Ptr", hWnd, "UInt", idObject&=0xFFFFFFFF, "Ptr"
, -VarSetCapacity(IID, 16) + NumPut(idObject == 0xFFFFFFF0 ? 0x46000000000000C0 : 0x719B3800AA000C81
, NumPut(idObject == 0xFFFFFFF0 ? 0x0000000000020400 : 0x11CF3C3D618736E0, IID, "Int64"), "Int64"), "Ptr*", pacc) = 0
Return ComObjEnwrap(9, pacc, 1)
}
;------------------------------------------------------------
;------------------------------------------------------------
GetCurrentUrlAccQuery(objAcc)
; Part of the Acc.ahk Standard Library by Sean (updated by jethrow) (via Joe Glines)
; Found at http://autohotkey.com/board/topic/77303-/?p=491516
;------------------------------------------------------------
{
Try Return ComObj(9, ComObjQuery(objAcc, "{618736e0-3c3d-11cf-810c-00aa00389b71}"), 1)
}
;------------------------------------------------------------
;------------------------------------------------------------
GetCurrentUrlAccChildren(objAcc)
; Part of the Acc.ahk Standard Library by Sean (updated by jethrow) (via Joe Glines)
; Found at http://autohotkey.com/board/topic/77303-/?p=491516
;------------------------------------------------------------
{
If ComObjType(objAcc,"Name") != "IAccessible"
ErrorLevel := "Invalid IAccessible Object"
Else
{
GetCurrentUrlAccInit()
cChildren := objAcc.accChildCount
Children := []
If DllCall("oleacc\AccessibleChildren", "Ptr", ComObjValue(objAcc), "Int", 0, "Int", cChildren, "Ptr"
, VarSetCapacity(varChildren, cChildren * (8 + 2 * A_PtrSize), 0) * 0 + &varChildren, "Int*", cChildren) = 0
{
Loop, %cChildren%
{
i := (A_Index - 1) * (A_PtrSize * 2 + 8) + 8
child := NumGet(varChildren, i)
Children.Insert(NumGet(varChildren, i - 8) = 9 ? GetCurrentUrlAccQuery(child) : child)
(NumGet(varChildren, i - 8) = 9 ? ObjRelease(child) : "")
}
Return (Children.MaxIndex() ? Children : "")
}
Else
ErrorLevel := "AccessibleChildren DllCall Failed"
}
}
;------------------------------------------------------------
;------------------------------------------------------------
LocationIsHTTP(strLocation)
;------------------------------------------------------------
{
return SubStr(strLocation, 1, 7) = "http://" or SubStr(strLocation, 1, 8) = "https://"
}
;------------------------------------------------------------
;------------------------------------------------------------
GetWebPageTitle(strLocation)
;------------------------------------------------------------
{
ToolTip, %lToolTipRetrievingWebPageTitle%
strHTML := Url2Var(strLocation)
ToolTip
RegExMatch(strHTML, "is)<title>(.*?)</title>", strTitle)
StringReplace, strTitle, strTitle, <title>
StringReplace, strTitle, strTitle, </title>
StringReplace, strTitle, strTitle, `r, , A
StringReplace, strTitle, strTitle, `t, %A_Space%, A
StringReplace, strTitle, strTitle, `n, %A_Space%, A
return NumDecode(Trim(strTitle, Chr(160))) ; Chr(160) to also trim non-breaking spaces
}
;------------------------------------------------------------
;------------------------------------------------------------
Url2Var(strUrl)
;------------------------------------------------------------
{
objWebRequest := ComObjCreate("WinHttp.WinHttpRequest.5.1")
/*
if (A_LastError)
; an error occurred during ComObjCreate (A_LastError probably is E_UNEXPECTED = -2147418113 #0x8000FFFFL)
BUT DO NOT ABORT because the following commands will be executed even if an error occurred in ComObjCreate (!)
*/
objWebRequest.Open("GET", strUrl)
objWebRequest.Send()
return (objWebRequest.StatusText() = "OK" ? objWebRequest.ResponseText() : "")
}
;------------------------------------------------------------
;------------------------------------------------------------
NumDecode(str)
; Extracted from Dec_XML() https://autohotkey.com/board/topic/29866-encoding-and-decoding-functions-v11/
; converts "é" or "é" to "é"
;------------------------------------------------------------
{
Loop
If RegexMatch(str, "S)(&#(\d+);)", dec) ; matches: &#[dec];
StringReplace, str, str, %dec1%, % Chr(dec2), All
Else If RegexMatch(str, "Si)(&#x([\da-f]+);)", hex) ; matches: &#x[hex];
StringReplace, str, str, %hex1%, % Chr("0x" . hex2), All
Else
Break
return str
}
;------------------------------------------------------------
Author of freeware Quick Access Popup, the powerful Windows folders, apps and documents launcher!
Now working on Quick Clipboard Editor
The Automator's Courses on AutoHotkey
Now working on Quick Clipboard Editor
The Automator's Courses on AutoHotkey
Re: Get the URL of the current (active) browser tab
thank you for making a great script even more awesome
JnLlnd wrote:If this can help, here is my full script for getting the URL and getting the web page title. Most of the code for getting the URL comes from this thread but code formatting and variables naming were adapted to my own style.
Tested with IE 11, Chrome and Firefox 57 and Edge 40. Alt-Q to test it.
Code: Select all
#SingleInstance force ; Skips the dialog box and replaces the old instance automatically g_strModernBrowsers := "ApplicationFrameWindow,Chrome_WidgetWin_0,Chrome_WidgetWin_1,Maxthon3Cls_MainFrm,Slimjet_WidgetWin_1,MozillaWindowClass" g_strLegacyBrowsers := "IEFrame,OperaWindowClass" ;------------------------------------------------------------ !q:: ;------------------------------------------------------------ strURL := "" WinGetClass, strClass, A if InStr(g_strModernBrowsers, strClass) strURL := GetCurrentUrlAcc(strClass) else if InStr(g_strLegacyBrowsers, strClass) strURL := GetCurrentUrlDDE(strClass) ; empty string if DDE not supported (or not a browser) if StrLen(strURL) MsgBox, % "Class: " . strClass . "`nURL: " . strURL . "`nTitle: " . GetWebPageTitle(strURL) else MsgBox, Current window is not a browser return ;------------------------------------------------------------ ;------------------------------------------------------------ GetCurrentUrlDDE(strClass) ; "GetCurrentUrlDDE" adapted from DDE code by Sean, (AHK_L version by maraskan_user) (via Joe Glines) ; Found at http://autohotkey.com/board/topic/17633-/?p=434518 ;------------------------------------------------------------ { WinGet, strServer, ProcessName, % "ahk_class " . strClass StringTrimRight, strServer, strServer, 4 intCodePage := (A_IsUnicode ? 0x04B0 : 0x03EC) ; 0x04B0 = CP_WINUNICODE, 0x03EC = CP_WINANSI DllCall("DdeInitialize", "UPtrP", idInst, "Uint", 0, "Uint", 0, "Uint", 0) hServer := DllCall("DdeCreateStringHandle", "UPtr", idInst, "Str", strServer, "int", intCodePage) hTopic := DllCall("DdeCreateStringHandle", "UPtr", idInst, "Str", "WWW_GetWindowInfo", "int", intCodePage) hItem := DllCall("DdeCreateStringHandle", "UPtr", idInst, "Str", "0xFFFFFFFF", "int", intCodePage) hConv := DllCall("DdeConnect", "UPtr", idInst, "UPtr", hServer, "UPtr", hTopic, "Uint", 0) hData := DllCall("DdeClientTransaction", "Uint", 0, "Uint", 0, "UPtr", hConv, "UPtr", hItem, "UInt", 1, "Uint", 0x20B0, "Uint", 10000, "UPtrP", nResult) ; 0x20B0 = XTYP_REQUEST, 10000 = 10s timeout sData := DllCall("DdeAccessData", "Uint", hData, "Uint", 0, "Str") DllCall("DdeFreeStringHandle", "UPtr", idInst, "UPtr", hServer) DllCall("DdeFreeStringHandle", "UPtr", idInst, "UPtr", hTopic) DllCall("DdeFreeStringHandle", "UPtr", idInst, "UPtr", hItem) DllCall("DdeUnaccessData", "UPtr", hData) DllCall("DdeFreeDataHandle", "UPtr", hData) DllCall("DdeDisconnect", "UPtr", hConv) DllCall("DdeUninitialize", "UPtr", idInst) csvWindowInfo := StrGet(&sData, "CP0") StringSplit, strWindowInfo, csvWindowInfo, `" ;"; comment to avoid a syntax highlighting issue in autohotkey.com/boards Return strWindowInfo2 } ;------------------------------------------------------------ ;------------------------------------------------------------ GetCurrentUrlAcc(strClass) ; Found at https://autohotkey.com/boards/viewtopic.php?f=6&t=3702&start=60 ;------------------------------------------------------------ { ; static or global? global nWindow global accAddressBar If (nWindow != WinExist("ahk_class " strClass)) ; reuses accAddressBar if it's the same window { nWindow := WinExist("ahk_class " strClass) accAddressBar := GetAddressBar(GetCurrentUrlAccObjectFromWindow(nWindow)) } Try sURL := accAddressBar.accValue(0) If (sURL == "") { WinGet, nWindows, List, % "ahk_class " strClass ; In case of a nested browser window as in the old CoolNovo (TO DO: check if still needed) If (nWindows > 1) { accAddressBar := GetAddressBar(GetCurrentUrlAccObjectFromWindow(nWindows2)) Try sURL := accAddressBar.accValue(0) } } If ((sURL != "") and (SubStr(sURL, 1, 4) != "http")) ; Modern browsers omit "http://" sURL := "http://" . sURL If (sURL == "") nWindow := -1 ; Don't remember the window if there is no URL Return sURL } ;------------------------------------------------------------ ;------------------------------------------------------------ GetAddressBar(accObj, accPath:="") ; "GetAddressBar" based in code by stealzy ; Found at https://autohotkey.com/boards/viewtopic.php?p=109548#p109548 ; IsUrl in this functions above replaced by my own code LocationIsHttp ;------------------------------------------------------------ { n := 0 Try If ((accObj.accRole(0) == 42) and StrLen(accObj.accValue(0)) and LocationIsHttp(accObj.accValue(0))) Return accObj Try If ((accObj.accRole(0) == 42) and StrLen(accObj.accValue(0)) and LocationIsHttp("http://" . accObj.accValue(0))) ; Modern browsers omit "http://" Return accObj For nChild, accChild in GetCurrentUrlAccChildren(accObj) { n++ currentPath := accPath . n . "." If IsObject(accAddressBar := GetAddressBar(accChild, currentPath)) Return accAddressBar } } ;------------------------------------------------------------ ;------------------------------------------------------------ GetCurrentUrlAccInit() ; Part of the Acc.ahk Standard Library by Sean (updated by jethrow) (via Joe Glines) ; Found at http://autohotkey.com/board/topic/77303-/?p=491516 ;------------------------------------------------------------ { static h If Not h h := DllCall("LoadLibrary", "Str", "oleacc", "Ptr") } ;------------------------------------------------------------ ;------------------------------------------------------------ GetCurrentUrlAccObjectFromWindow(hWnd, idObject = 0) ; Part of the Acc.ahk Standard Library by Sean (updated by jethrow) (via Joe Glines) ; Found at http://autohotkey.com/board/topic/77303-/?p=491516 ;------------------------------------------------------------ { GetCurrentUrlAccInit() If DllCall("oleacc\AccessibleObjectFromWindow", "Ptr", hWnd, "UInt", idObject&=0xFFFFFFFF, "Ptr" , -VarSetCapacity(IID, 16) + NumPut(idObject == 0xFFFFFFF0 ? 0x46000000000000C0 : 0x719B3800AA000C81 , NumPut(idObject == 0xFFFFFFF0 ? 0x0000000000020400 : 0x11CF3C3D618736E0, IID, "Int64"), "Int64"), "Ptr*", pacc) = 0 Return ComObjEnwrap(9, pacc, 1) } ;------------------------------------------------------------ ;------------------------------------------------------------ GetCurrentUrlAccQuery(objAcc) ; Part of the Acc.ahk Standard Library by Sean (updated by jethrow) (via Joe Glines) ; Found at http://autohotkey.com/board/topic/77303-/?p=491516 ;------------------------------------------------------------ { Try Return ComObj(9, ComObjQuery(objAcc, "{618736e0-3c3d-11cf-810c-00aa00389b71}"), 1) } ;------------------------------------------------------------ ;------------------------------------------------------------ GetCurrentUrlAccChildren(objAcc) ; Part of the Acc.ahk Standard Library by Sean (updated by jethrow) (via Joe Glines) ; Found at http://autohotkey.com/board/topic/77303-/?p=491516 ;------------------------------------------------------------ { If ComObjType(objAcc,"Name") != "IAccessible" ErrorLevel := "Invalid IAccessible Object" Else { GetCurrentUrlAccInit() cChildren := objAcc.accChildCount Children := [] If DllCall("oleacc\AccessibleChildren", "Ptr", ComObjValue(objAcc), "Int", 0, "Int", cChildren, "Ptr" , VarSetCapacity(varChildren, cChildren * (8 + 2 * A_PtrSize), 0) * 0 + &varChildren, "Int*", cChildren) = 0 { Loop, %cChildren% { i := (A_Index - 1) * (A_PtrSize * 2 + 8) + 8 child := NumGet(varChildren, i) Children.Insert(NumGet(varChildren, i - 8) = 9 ? GetCurrentUrlAccQuery(child) : child) (NumGet(varChildren, i - 8) = 9 ? ObjRelease(child) : "") } Return (Children.MaxIndex() ? Children : "") } Else ErrorLevel := "AccessibleChildren DllCall Failed" } } ;------------------------------------------------------------ ;------------------------------------------------------------ LocationIsHTTP(strLocation) ;------------------------------------------------------------ { return SubStr(strLocation, 1, 7) = "http://" or SubStr(strLocation, 1, 8) = "https://" } ;------------------------------------------------------------ ;------------------------------------------------------------ GetWebPageTitle(strLocation) ;------------------------------------------------------------ { ToolTip, %lToolTipRetrievingWebPageTitle% strHTML := Url2Var(strLocation) ToolTip RegExMatch(strHTML, "is)<title>(.*?)</title>", strTitle) StringReplace, strTitle, strTitle, <title> StringReplace, strTitle, strTitle, </title> StringReplace, strTitle, strTitle, `r, , A StringReplace, strTitle, strTitle, `t, %A_Space%, A StringReplace, strTitle, strTitle, `n, %A_Space%, A return NumDecode(Trim(strTitle, Chr(160))) ; Chr(160) to also trim non-breaking spaces } ;------------------------------------------------------------ ;------------------------------------------------------------ Url2Var(strUrl) ;------------------------------------------------------------ { objWebRequest := ComObjCreate("WinHttp.WinHttpRequest.5.1") /* if (A_LastError) ; an error occurred during ComObjCreate (A_LastError probably is E_UNEXPECTED = -2147418113 #0x8000FFFFL) BUT DO NOT ABORT because the following commands will be executed even if an error occurred in ComObjCreate (!) */ objWebRequest.Open("GET", strUrl) objWebRequest.Send() return (objWebRequest.StatusText() = "OK" ? objWebRequest.ResponseText() : "") } ;------------------------------------------------------------ ;------------------------------------------------------------ NumDecode(str) ; Extracted from Dec_XML() https://autohotkey.com/board/topic/29866-encoding-and-decoding-functions-v11/ ; converts "é" or "é" to "é" ;------------------------------------------------------------ { Loop If RegexMatch(str, "S)(&#(\d+);)", dec) ; matches: &#[dec]; StringReplace, str, str, %dec1%, % Chr(dec2), All Else If RegexMatch(str, "Si)(&#x([\da-f]+);)", hex) ; matches: &#x[hex]; StringReplace, str, str, %hex1%, % Chr("0x" . hex2), All Else Break return str } ;------------------------------------------------------------
Re: Get the URL of the current (active) browser tab
The script doesn't work with the new Firefox-Version 57 ("Quantum") anymore. Who can help us, me and the script?
Re: Get the URL of the current (active) browser tab
It re-tested it and it is working with Firefox 57 on some websites (for example, on Twitter.com).... but not on others. I could not tell why. We would need again input from browsers experts here?Johnny R wrote:The script doesn't work with the new Firefox-Version 57 ("Quantum") anymore. Who can help us, me and the script?
Author of freeware Quick Access Popup, the powerful Windows folders, apps and documents launcher!
Now working on Quick Clipboard Editor
The Automator's Courses on AutoHotkey
Now working on Quick Clipboard Editor
The Automator's Courses on AutoHotkey
Re: Get the URL of the current (active) browser tab
Where is our friend atnbueno? Hallo atnbueno!
Return to “Scripts and Functions (v1)”
Who is online
Users browsing this forum: No registered users and 70 guests