Get Title and Url of the active browser tab

Post your working scripts, libraries and tools for AHK v1.1 and older
User avatar
rommmcek
Posts: 1480
Joined: 15 Aug 2014, 15:18

Get Title and Url of the active browser tab

06 Jan 2021, 10:26

Link: GetAccData() v6.45 - function to retrieve Title and Url of the desired browser tab
(This is fork of atnbueno's GetActiveBrowserURL() function.)

Special thanks to malcev for the improvement of the initializing the Acc and buffering the AccObj for IE and Vivaldi.
Last edited by rommmcek on 10 Apr 2021, 10:16, edited 13 times in total.
BoBo
Posts: 6564
Joined: 13 May 2014, 17:15

Re: Get Title and Url of the desired browser tab

06 Jan 2021, 11:15

The coloring & sizing of your link make it kinda challenging to spot it as one. JM2€C :think:
ahk7
Posts: 577
Joined: 06 Nov 2013, 16:35

Re: Get Title and Url of the active browser tab

06 Jan 2021, 13:30

I get an error on Firefox 84.0.1 (64-bit); Windows 10, Version 10.0.19041.685 twice when I try to get the URL, works in Chrome though. (atnbueno's hasn't worked for me with Firefox for a long time either)

Code: Select all

---------------------------
GetAccData.ahk
---------------------------
Error:  0x80004003 - Invalid pointer
Source:        (null)
Description:    (null)
HelpFile:        (null)
HelpContext:    0

Specifically: accName

    Line#
    017: accRR := ""
    017: accData := ""
    018: nWin:= WinExist(WinId), ParseAccData( GetAccObjectFromWindow(nWin) )
    019: }
    021: {
    023: if !accRR
    023: {
--->    024: accData? "": accData:= [accObj.accName(0)]
    025: Try
    025: if accObj.accName(0) && accObj.accValue(0) && accObj.accRole(0) = 42
    026: accData.2:= SubStr(u:=accObj.accValue(0), 1, 4)="http"? u: "http://" u, accRR:= 1
    027: For nChild,accChild in (GetAccChildren(accObj), n:=0)
    028: currPath:= accPath ++n ".", ParseAccData(accChild, currPath)
    029: }
    030: }

Continue running the script?
---------------------------
Yes   No
---------------------------

---------------------------
GetAccData.ahk
---------------------------
Error:  0x80004003 - Invalid pointer
Source:        (null)
Description:    (null)
HelpFile:        (null)
HelpContext:    0

Specifically: accChildCount

    Line#
    044: Return,ComObj(9, ComObjQuery(objAcc, "{618736e0-3c3d-11cf-810c-00aa00389b71}"), 1)
    045: }
    047: {
    048: if ComObjType(objAcc,"Name") != "IAccessible"
    049: ErrorLevel := "Invalid IAccessible Object"
    050: Else
    050: {
--->    051: cChildren:= objAcc.accChildCount, Children:= []
    052: 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
    052: {
    054: Loop,cChildren
    054: {
    055: i:= (A_Index - 1) * (A_PtrSize * 2 + 8) + 8, child:= NumGet(varChildren, i)
    056: Children.Insert(NumGet(varChildren, i - 8) = 9? GetAccQuery(child): child)
    057: NumGet(varChildren, i - 8) != 9? "": ObjRelease(child)

Continue running the script?
---------------------------
Yes   No
---------------------------
User avatar
rommmcek
Posts: 1480
Joined: 15 Aug 2014, 15:18

Re: Get Title and Url of the active browser tab

06 Jan 2021, 15:28

ahk7 wrote:
06 Jan 2021, 13:30
I get an error on Firefox 84.0.1 (64-bit)
Thanks for the feedback!
I was on FF 84.0.1 (32-bit) and now I installed FF 84.0.2 (64-bit) and have no such issues. However I'm on Win10 Home Version 1803 OS Build 17134.1. [Edit 1]: And AutoHotkey v1.1.31.01.
For now I updated the code with two additional try's, but am not sure how it will respond on error.

P.s.: Does Acc Viewer.ahk throw error when working on FF? [Edit 2]: Does atnbueno's code throw error or just yield wrong tab?

[Edit3]: Error: 0x80004003 - Invalid pointer might indicated problems with driver or antivirus software. For the former don't know how to fix it, for the latter you can try to disable it.
User avatar
rommmcek
Posts: 1480
Joined: 15 Aug 2014, 15:18

Re: Get Title and Url of the active browser tab

08 Jan 2021, 20:02

Updated the function to add some turbo speed for subsequent queries in a given browser instance (except for IE and Vivaldi).
User avatar
rommmcek
Posts: 1480
Joined: 15 Aug 2014, 15:18

Re: Get Title and Url of the active browser tab

14 Jan 2021, 12:00

New update. Simplified the code and performing the Obj history reset.
MancioDellaVega
Posts: 84
Joined: 16 May 2020, 12:27
Location: Italy

Re: Get Title and Url of the active browser tab

14 Jan 2021, 13:37

rommmcek wrote:
14 Jan 2021, 12:00
New update. Simplified the code and performing the Obj history reset.
Am i ? Or the link doesn't work??
Courses on AutoHotkey
garry
Posts: 3795
Joined: 22 Dec 2013, 12:50

Re: Get Title and Url of the active browser tab

14 Jan 2021, 15:46

GetAccData Version 4.35 works fine for me ( chrome ) ... but yes at the moment .... The selected attachment does not exist anymore.
EDIT : few minutes later > LINK works ... thank you @rommmcek
Last edited by garry on 14 Jan 2021, 16:12, edited 1 time in total.
AHKStudent
Posts: 1472
Joined: 05 May 2018, 12:23

Re: Get Title and Url of the active browser tab

14 Jan 2021, 22:48

works great, i'd change google.exe to chrome.exe
User avatar
rommmcek
Posts: 1480
Joined: 15 Aug 2014, 15:18

Re: Get Title and Url of the active browser tab

15 Jan 2021, 05:43

If you mean the parameter of the GetAccData(), your right! Note that normally there's no need to specify the parameter, as default will work on active window (I'm sure you know it and take this as a side note for less advanced users).
MancioDellaVega
Posts: 84
Joined: 16 May 2020, 12:27
Location: Italy

Re: Get Title and Url of the active browser tab

16 Jan 2021, 13:06

In my case i have this result...

Image


i have
Windows 10 home 1909 32bit
Chrome 87.0.4280.141
Autohotkey 1.1.33.01
Courses on AutoHotkey
User avatar
rommmcek
Posts: 1480
Joined: 15 Aug 2014, 15:18

Re: Get Title and Url of the active browser tab

16 Jan 2021, 14:25

Try to close Find dialog (launched via ^f) if it is opened and press ^F8.
MancioDellaVega
Posts: 84
Joined: 16 May 2020, 12:27
Location: Italy

Re: Get Title and Url of the active browser tab

17 Jan 2021, 08:55

Nothing...the address of the page is always a number... 😞
Courses on AutoHotkey
burque505
Posts: 1736
Joined: 22 Jan 2017, 19:37

Re: Get Title and Url of the active browser tab

17 Jan 2021, 09:59

@rommmcek, @MancioDellaVega, this works fine for me on Win7 SP 1, 64-bit, AHK 1.33.02, but on Win10 Pro, 10.0.19041, I get the same results as @MancioDellaVega.
Regards,
burque505
garry
Posts: 3795
Joined: 22 Dec 2013, 12:50

Re: Get Title and Url of the active browser tab

17 Jan 2021, 14:40

GetAccData works fine for me , Windows-10 64 bit 10.0.19042 , Chrome 64-bit
I used longtime this ahk basic script , copy also marked text ( get URL / Title / Text )

Code: Select all

;- start this script, copy text in browser chrome, use alt+F12 
;- see result in file %a_desktop%\URL_TITLE_TEXT.txt = URL / DATE / TITLE / marked TEXT
;- copie el texto marcado en el navegador Chrome
;------------------------------------------------------------------------------------------- 
/*
;-- result example :
https://www.pagina12.com.ar/317842-india-lanza-el-mayor-operativo-de-vacunacion-en-el-mundo
Copied = domingo enero 2021-01-17  10:26 UTC
India lanza el mayor operativo de vacunación en el ... | Página12
India inició la campaña de vacunación más grande del mundo contra la covid-19. 
Con un población de 1.300 millones de habitantes, el país estima que para julio podrán vacunar a 300 millones de personas. 
---------------------
*/
/*
see also:  Get Title and Url of the active browser tab  from user rommmcek
https://www.autohotkey.com/boards/viewtopic.php?f=6&t=85383
*/
;---------------------------------------------------------------------------------------------
#warn
#NoEnv
setworkingdir,%a_scriptdir%
FormatTime,Argentina       ,%a_nowutc% L0x2C0A, dddd MMMM yyyy-MM-dd  HH:mm  ;
timestamp=-------- Copied = %Argentina% UTC  ---------------
;-https://www.autohotkey.com/docs/misc/Languages.htm  languageCode_2C0A := "Spanish_Argentina"
f1=%a_desktop%\URL_TITLE_TEXT.txt
y:=" - Google Chrome"              ;- delimiter for strsplit
u:=" - YouTube - Google Chrome"
*~$!F12::
#If WinActive("ahk_exe chrome.exe")  ;- example for chrome browser
clipboard=
;-- copy marked text  -----------
text=
sendinput, ^c
clipwait,2,1
sleep,200
if errorlevel=0
 {
 Text:=clipboard
 sleep,200
 text1 := RegExReplace(text, "([.!?¿] )", "$1`r`n")  ;- new lines after .!?¿
 clipboard:=""
 }
;-- copy URL ------------
 url:=""
 send,^l
 sleep,200
 send,^c 
 clipwait,2,1
 if errorlevel=0
   {
   url:=clipboard
   send,^{end}
   }
 sleep,200
 clipboard=
;--- copy title ---------
 title=
 a=
 WinGetActiveTitle, title
 if title contains Youtube
   a:=StrSplit(title,u)
 else
   a:=StrSplit(title,y)
 title:=a[1]
;--- remove empty lines----
 Loop
  {
  StringReplace,text1,text1, `r`n`r`n, `r`n, UseErrorLevel
  if ErrorLevel = 0  
        break
  }
;--------------------------
if text<>
  fileappend,%url%`r`n%timestamp%`r`n%title%`r`n%text1%`r`n---------------------`r`n,%f1%,UTF-8
else
  fileappend,%url%`r`n%timestamp%`r`n%title%`r`n------------------`r`n,%f1%,UTF-8
;send,^r       ;- reload page / remove mark from url                
Splashimage,,b w700 h350 x100 Y400 CWsilver m9 b fs10 zh0,%url%`n%title%`n%text1%
sleep,1800
Splashimage, off
;----------------------
url      :=""
title    :="" 
text     :="" 
text1    :=""
;clipboard:=""
#if
return
;========================================
User avatar
rommmcek
Posts: 1480
Joined: 15 Aug 2014, 15:18

Re: Get Title and Url of the active browser tab

24 Jan 2021, 09:22

Thanks for the feedback!
MancioDellaVega wrote:...the address of the page is always a number...
The number indicates how many miliseconds took it to display the result, Url (address) is obviously blank.
You could try to restart Chrome or use parameter e.g. GetAccData("chorme.exe")...
burque505 wrote:...on Win10 Pro, 10.0.19041, I get the same results...
You could try to replace try if accObj.accRole(0) = 42 && accObj.accName(0) && accObj.accValue(0)
with try InStr(accObj.Value(0), ".")
or try InStr(accObj.Value(0), "/") (not sure if any address contains /)
or try InStr(accObj.Value(0), ".") && InStr(accObj.Value(0), "/")
If still does not work you can try to replace Value(0) with Name(0) in above three lines.

P.s.: If all this does not help I could post my AccSpy based on this code if anybody is willing to play with it. It is very user unfriendly, but for me the only one which retrieves e.g. AccPath(s) for any browser in fact for any window correctly.
burque505
Posts: 1736
Joined: 22 Jan 2017, 19:37

Re: Get Title and Url of the active browser tab

24 Jan 2021, 10:50

@rommmcek, my Win10 Pro just updated. I no longer experience the errors I and @MancioDellaVega had. There's an interesting side-effect - see below. Maybe this could be expanded to report accurately for non-browser apps?
Word - help..PNG
Word - help..PNG (9.9 KiB) Viewed 5641 times
Scite.png
Scite.png (8.67 KiB) Viewed 5641 times
Notepad.png
Notepad.png (6.69 KiB) Viewed 5641 times
Regards,
burque505
User avatar
rommmcek
Posts: 1480
Joined: 15 Aug 2014, 15:18

Re: Get Title and Url of the active browser tab

24 Jan 2021, 11:12

Thanks again for the feedback!

Based on that, if anybody has issues with GetAccData() it is recommended to update OS as well!

As I mentioned in postscriptum in my previous post, this kind of code works on any window. So WinTitle should be always displayed (if there is one) and address is obviously unpredictable on non browser windows... If you want to filter other windows then use parameter e.g.: GetAccData("chrome.exe")
burque505
Posts: 1736
Joined: 22 Jan 2017, 19:37

Re: Get Title and Url of the active browser tab

24 Jan 2021, 11:43

@rommmcek, thanks again to you! I forgot to ask for AccSpy.
@rommmcek said:
P.s.: If all this does not help I could post my AccSpy based on this code if anybody is willing to play with it. It is very user unfriendly, but for me the only one which retrieves e.g. AccPath(s) for any browser in fact for any window correctly.
I'd be very happy to see it.
Regards,
burque505

Return to “Scripts and Functions (v1)”

Who is online

Users browsing this forum: No registered users and 99 guests