Page 1 of 1

In Google Chrome die aktive Url ermitteln

Posted: 05 Apr 2014, 11:12
by Johnny R
Mit diesem Code soll es möglich sein, die gerade in Google Chrome aktive Url zu ermitteln, vgl.:
http://www.autohotkey.com/board/topic/1 ... le-chrome/
Bei mir (AHK 1.1.14.03 A32; WinXP SP3) klappt das aber schon in der 2. Zeile (bei AccChrome := Acc_ObjectFromWindow(hwndChrome)) nicht. Ich bekomme kein Ergebnis.

Das hier mit B = chrome funktioniert leider auch nicht, was daran zu liegen scheint, daß DDE von Chrome offenbar nicht unterstützt wird, vgl.:
https://groups.google.com/forum/#!topic ... bAFFHIesSs

Weiß bitte jemand, wie das ggf. gehen könnte?

Code: Select all

; vgl.:
; http://www.autohotkey.com/board/topic/103178-how-to-get-the-current-url-in-google-chrome/
#INCLUDE acc.ahk ; http://www.autohotkey.com/board/topic/77303-acc-library-ahk-l-updated-09272012/page-2

hwndChrome := WinExist("ahk_class Chrome_WidgetWin_1")
AccChrome := Acc_ObjectFromWindow(hwndChrome)
AccAddressBar := GetElementByName(AccChrome, "Address and search bar")
MsgBox % AccAddressBar.accValue(0)

GetElementByName(AccObj, name) {
   if (AccObj.accName(0) = name)
      return AccObj
   
   for k, v in Acc_Children(AccObj)
      if IsObject(obj := GetElementByName(v, name))
         return obj
}

Re: In Google Chrome die aktive Url ermitteln

Posted: 08 Apr 2014, 23:59
by just me
Moin,

das Du hier keine Antwort bekommst, liegt wahrscheinlich daran, dass sich hier keiner mit dieser Materie auskennt. Ich denke, diese Frage ist oben besser aufgehoben.

Re: In Google Chrome die aktive Url ermitteln

Posted: 09 Apr 2014, 00:19
by nnnik
#INCLUDE acc.ahk
Hast du dieses Include runtergeladen?

Re: In Google Chrome die aktive Url ermitteln

Posted: 09 Apr 2014, 01:37
by Johnny R
Ja, das Include acc.ahk habe ich (selbstverständlich) heruntergeladen und im Skriptordner abgelegt, vgl.:
http://www.autohotkey.com/board/topic/7 ... -09272012/
Es kommt auch keine Fehlermeldung. Die Variable AccChrome ist einfach nur ein Leerstring, weshalb dann (natürlich) auch das weitere Skript nicht funktioniert.

Re: In Google Chrome die aktive Url ermitteln

Posted: 09 Apr 2014, 01:50
by nnnik
Es muss nicht unbedingt leer sein wenn es ein Leerstrting ist.
Msgbox % isObject(AccChrome)
Würde wenn ich raten müsste 1 zurückgeben.

Re: In Google Chrome die aktive Url ermitteln

Posted: 09 Apr 2014, 05:09
by Johnny R
Wunderbar. Das kann sein. Das werde ich gleich heute abend versuchen.

Unterstellt, Du hast Recht: Kann es sein, daß die Syntax von

Code: Select all

AccAddressBar := GetElementByName(AccChrome, "Address and search bar")
falsch ist und hier der Fehler liegt? Hiernach müßte es nämlich möglicherweiese heißen:

Code: Select all

AccAddressBar := AccChrome.GetElementByName("Address and search bar")
? Vgl. a.:
http://www.autohotkey.com/board/topic/4 ... -tutorial/

Ich melde mich wieder...

Re: In Google Chrome die aktive Url ermitteln

Posted: 09 Apr 2014, 05:37
by nnnik
Dann teste doch einfach per MSgbox % isfunc("GetElementByName")
Ob die funktion existiert.

Re: In Google Chrome die aktive Url ermitteln

Posted: 09 Apr 2014, 11:58
by Johnny R
@nnnik, Du hattest Recht. Die Variable AccChrome war wirklich ein Objekt und kein Leerstring. Aber weiter kommt ich trotzdem nicht... :(

Re: In Google Chrome die aktive Url ermitteln

Posted: 30 May 2014, 13:40
by atnbueno
(I'm sorry I don't speak German but maybe this will help)

I recently had to use Acc.ahk and found out it is locale dependant. For example, the code above only works for me if I change "Address and search bar" by "Barra de direcciones y de búsqueda " (I use Windows in Spanish). Not only must be encoded in ANSI to work, but it also needs the space at the end. I found out the proper value using AccViewer.ahk.

HTH,
Antonio

Re: In Google Chrome die aktive Url ermitteln

Posted: 30 May 2014, 14:13
by GEV
Dank atnbueno habe ich es so geschafft:

Code: Select all

hwndChrome := WinExist("ahk_class Chrome_WidgetWin_1")
AccChrome := Acc_ObjectFromWindow(hwndChrome)
AccAddressBar := GetElementByName(AccChrome, "Adress- und Suchleiste")
AddressBarText := % AccAddressBar.accValue(0)

MsgBox %AddressBarText%

GetElementByName(AccObj, name) {
   if (AccObj.accName(0) = name)
      return AccObj
   
   for k, v in Acc_Children(AccObj)
      if IsObject(obj := GetElementByName(v, name))
         return obj
}

#INCLUDE acc.ahk ; http://www.autohotkey.com/board/topic/77303-acc-library-ahk-l-updated-09272012/page-2

Re: In Google Chrome die aktive Url ermitteln

Posted: 04 Jun 2014, 12:39
by Johnny R
Vielen Dank, Euch beiden! Mit Eurem Code funktioniert das jetzt bestens. Ich hatte die Hoffnung schon aufgegeben, daß sich da noch etwas tut...

Merkwürdig ist es aber schon, daß der Code je nach verwendeter Sprache unterschiedlich aussieht. Besser wäre es, wenn Englisch immer richtig wäre.

Re: In Google Chrome die aktive Url ermitteln

Posted: 04 Jun 2014, 15:57
by atnbueno
Hello again.

I've modified the code above to work (I hope) in any language (use it instead of GetElementByName)

Code: Select all

GetFirstElementWithBothNameAndValue(AccObj) {
	Try If ((AccObj.accName(0) != "") and (AccObj.accValue(0) != ""))
		Return AccObj
	For k, v in Acc_Children(AccObj)
		If IsObject(obj := GetFirstElementWithBothNameAndValue(v))
			Return obj
}
It is based in the fact that the address bar is the first element that has both a name and a value. I've tested it on Chrome 35 and 37 in both English and Spanish versions of Windows 7.

This function will stop working once Google enables the "Origin Chip", but I'm already working on a more robust solution.

Re: In Google Chrome die aktive Url ermitteln

Posted: 08 Jun 2014, 13:34
by atnbueno
And here it is: Get the URL of the current (active) browser tab

The script is language independent and supports most modern browsers (even some future ones :P)


Regards,
Antonio

Re: In Google Chrome die aktive Url ermitteln

Posted: 09 Jun 2014, 11:55
by Johnny R
@Antonio, funktioniert wunderbar, auch mit AutoHotkeyA32. Hoffentlich sieht man Dich hier in Deutschland bald einmal wieder! Grüße nach Spanien und viel Glück für die WM! ;)