Jump to content

Sky Slate Blueberry Blackcurrant Watermelon Strawberry Orange Banana Apple Emerald Chocolate
Photo

How to get the current URL in Google Chrome



  • Please log in to reply
7 replies to this topic
JasonA
  • Members
  • 2 posts
  • Last active: Feb 26 2015 09:33 PM
  • Joined: 14 Mar 2014

Hello,

ever since version 32 of Google Chrome, AHK/Window Spy no longer can see the active url in the url bar.

For example, this no longer works:

ControlGetText, str, % "Chrome_OmniboxView" Chr( 48 + A_Index )

 

The only way is to interrupt the user and Send,!d then Send ^c which is not desired.

 

Can someone figure out a way to find the url of the active open tab in Google Chrome?

 

Even desperate enough for a Chrome extension or to use a developer build etc.

 

Will gladly reward whoever provides a working solution!

 

Thanks,
Jason



uname
  • Members
  • 194 posts
  • Last active: Oct 17 2015 08:46 AM
  • Joined: 13 Jun 2012
✓  Best Answer
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
}
Acc.ahk required

JasonA
  • Members
  • 2 posts
  • Last active: Feb 26 2015 09:33 PM
  • Joined: 14 Mar 2014

Wow thank you - truly helped. I sent you a PM.

 

Can you see if we can grab the contents on the webpage as well? (without having to URLDownloadtoFile the url ...it would speed things up dramatically for us)



Jimmy2Times
  • Members
  • 65 posts
  • Last active: Jul 15 2014 07:56 PM
  • Joined: 07 Apr 2004

(hit save twice oops)


Edited by Payam, 19 May 2014 - 11:35 PM.


Jimmy2Times
  • Members
  • 65 posts
  • Last active: Jul 15 2014 07:56 PM
  • Joined: 07 Apr 2004

Can anyone assist?

Would like to grab the currently loaded contents of the webpage (i.e. the body) as well? (without having to URLDownloadtoFile the url ...it would speed things up dramatically for us)



atnbueno
  • Members
  • 91 posts
  • Last active: Feb 16 2016 07:04 PM
  • Joined: 24 Mar 2007

Thanks uname. Your code has cleared up a problem I had with aac.ahk.

 

A small warning: the string "Address and search bar" is locale dependant (that is, it depends on the language of your Windows version). For me it's "Barra de direcciones y de búsqueda " (yes, with an space at the end, and because of the accented "u" it needs to be ANSI encoded :-P).

 

Also, Payam, you may find useful to play a bit with AccViewer.ahk. For what I've seen with a quick look, the source of the webpage is not acessible directly via ACC.

 

 

Regards,

Antonio



atnbueno
  • Members
  • 91 posts
  • Last active: Feb 16 2016 07:04 PM
  • Joined: 24 Mar 2007
Hello again.
 
I found a workaround for the language issue and I've assembled a script to find the current URL in most modern browsers (even some future ones happy.png)
 
If you look at the code you'll see uname's influence wink.png
 
 
Regards,
Antonio

yukisaw
  • Members
  • 1 posts
  • Last active: Oct 03 2014 09:13 PM
  • Joined: 02 Oct 2014

Ty, Uname.

I change this code for any locale, maybe someone need it.

Function:

GetElementByText(AccObj, text) {
	try
   if (AccObj.accValue(0) = text)
      return AccObj
   
   for k, v in Acc_Children(AccObj)
      if IsObject(obj := GetElementByText(v, text))
         return obj
}

SubFunction:

GetAddressBar:
	send !{vk44sc02} ; ALT+D
	back := clipboard
	clipboard :=
	send ^{vk43sc02e} ;CTRL+C
	ClipWait
		send GetAddress
		hwndChrome := WinExist("ahk_class Chrome_WidgetWin_1")
		AccChrome := Acc_ObjectFromWindow(hwndChrome)
		Address := GetElementByText(AccChrome, "GetAddress")
	send ^{vk41sc01e} ; CTRL+A
	send ^{vk56sc02f} ; CTRL+V
	sleep 100
	clipboard := back
		Addr := 1
return

Call:

$^Left::
ifWinActive ahk_class Chrome_WidgetWin_1
	{
if Addr != 1
GoSub GetAddressBar
	Chrome_Address := Address.accValue(0)
;any code what you want
;like this:	if RegExMatch(Chrome_Address, "autohotkey\.com")
}
return

Acc.ahk required.