Jump to content

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

Get the URL of the current (active) browser tab


  • Please log in to reply
34 replies to this topic
atnbueno
  • Members
  • 91 posts
  • Last active: Feb 16 2016 07:04 PM
  • Joined: 24 Mar 2007

Hello everyone.

Short version: The code below finds out the URL of the current (active) browser tab for most of the modern browsers.

Long version:
How to get the URL of the browser tab I'm using? The problem is quite common and there have been several scripts to tackle it here in the forum.

The best solution for quite sometime (IMHO) was Sean's DDE code but unfortunately Google Chrome doesn't support DDE. Recent changes to Chrome invalidated the Chrome_OmniboxView workaround so I didn't knew how to get it until I saw uname's use of the ACC library (Sean strikes again :)). uname's code depended on the language used in Windows (I use Win7 x64 in Spanish) but I found out a workaround. I even managed to extend my solution to cover Chromium-based browsers (like the new Opera), and even got it to work in Maxthon.

Anyway, the code below finds out the URL of the current (active) browser tab. I've tested it successfully (on Win7 x64 Spanish) with the following browsers:

  • Google Chrome 46
  • Mozilla Firefox 41
  • Internet Explorer 11
  • Opera 32
  • Microsoft Edge 20
  • Opera 12
  • Google Chrome 37-38 (Canary)
  • Maxthon 4.4
  • Iron 45
  • Coowon 1.6.8.0
  • CoolNovo 2.0.9.20
  • Slimjet 5.0.11.0

I'd appreciate any feedback, particularly if it DOESN'T work tongue.png
 
Download: GetActiveBrowserURL.ahk

See the current script in the new board: https://autohotkey.com/boards/viewtopic.php?t=3702

Regards,
Antonio
 
EDIT 2014-06-17:
- Faster in Chromium browsers: After the first use, successive queries are instantaneous (faster than DDE!) Thanks to XeroByte for the nudge ;-)
- Improved error messages in the hotkey example
- Tested without problems in all AutoHotkey versions (U32, A32, U64) and also in Windows 8.1
 
EDIT 2014-07-05:
- Now it works with CoolNovo (blame Kudos happy.png) and (probably) any other Chromium-based nested-window browsers

EDIT 2014-10-18:
- Now it works with Microsoft Edge (only tested via VM) and Slimjet (both suggestions by Kudos)
- Better URL detection (thanks LarryC for the feedback)
- Added workaround for runtime errors suggested by Kipp (in the old forum) a year ago
- Removed support for Google's failed Origin Chip experiment

 

EDIT 2015-12-31:

- This board will be read-only from now on. Development of this script will continue in the new board: https://autohotkey.c...opic.php?t=3702



DataLife
  • Members
  • 1022 posts
  • Last active: Nov 27 2015 01:09 AM
  • Joined: 27 Apr 2008
Works great on AutoHotkey 1.1.15.00 Ansi 32bit windows 7 64bit,
Check out my scripts.  (MyIpChanger) (XPSnap) (SavePictureAs) All my scripts are tested on Windows 7, AutoHotkey 32 bit Ansi unless otherwise stated.

ozzii
  • Members
  • 167 posts
  • Last active: Oct 30 2015 04:54 PM
  • Joined: 23 Mar 2011
Latest French FF (portable) with latest AHK_L Unicode not working

---------------------------GetActiveBrowserURL.ahk---------------------------Not a browser or browser not supported (MozillaWindowClass)---------------------------OK   ---------------------------


garry
  • Spam Officer
  • 3219 posts
  • Last active: Sep 20 2018 02:47 PM
  • Joined: 19 Apr 2005

script from atnbueno works for me , maybe use msgbox alwaysontop

msgbox, 262208, , Test

otherwise , only for firefox, I used this before

;- copy firefox url
;----------- ALT+F3 --------------------------------------
*~$!F3::
C1=
Clipboard := ""
send,!s
sleep,100
send,^c
sleep,100
ClipWait,1
C1:=clipboard
if (ErrorLevel)
    return
msgbox, 262208, ,%c1%,2
return
;==========================================================



bruno
  • Members
  • 635 posts
  • Last active: Nov 04 2015 02:26 PM
  • Joined: 07 Mar 2011

Script by atnbueno works for me, too! (Using Firefox)



Kudos
  • Members
  • 39 posts
  • Last active: Sep 27 2015 09:06 AM
  • Joined: 21 Aug 2006

Hi, doesn't work in Coolnovo 2.0.9.20 - based on chromium browser (like Google Chrome).

 

It would be awesome if you could provide a fix! Thanks!  :D



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

Thanks DataLife, ozzii, garry, bruno, and Kudos for the early feedback.
 
ozzii and Kudos, can you give me more information/context about your problem? I've tested the French Firefox from PortableApps.comand Coolnovo and they work here:
http://dl.dropboxuse...le_Fx_fr_OK.png

http://dl.dropboxuse...Coolnovo_OK.png

 

 

Regards,

Antonio

 

 

EDIT: What the ...?!? It stopped working in another test with Coolnovo. And now it works again. Now I'm baffled. And now I don't like Coolnovo :p



ozzii
  • Members
  • 167 posts
  • Last active: Oct 30 2015 04:54 PM
  • Joined: 23 Mar 2011
Well... The installed version works but not the portable. But the 2 profiles are completely different. Maybe an extension who do this. Nevermind. This was just a test.

XeroByte
  • Members
  • 20 posts
  • Last active: Nov 11 2015 01:31 AM
  • Joined: 04 Nov 2013

This is very impressive! Thanks Atnbueno!

 

I will certainly keep your method among my collected useful utilities, i especially love how it works in so many different browsers. However for the time being I think i will continue using my current chrome-url-grabbing method which is a lot messier and requires a special setup with a browser extension.

The method I use is more-or-less instant (assuming the web page has finished loading) whereas your method works a lot slower (i only tested in chrome) consistently taking more than 500ms. is there anything that can be done about that?

 

For anyone's future reference, here is my current method:

#u:: msgbox % GetChromeURL()

GetChromeURL(){ 
	; use Chrome Ext "Url in title" - to get Chrome URL cleanly found here https://chrome.google.com/webstore/detail/url-in-title/ignpacbgnbnkaiooknalneoeladjnfgb?hl=en
	;~ The setup of the Extension settings needs to be exactly like this: {title} |-| {protocol}://{hostname}{port}/{path}{args}{hash}
	StopLoopAt= ; := A_Now
	EnvAdd,StopLoopAt,10,Seconds
	loop{ ;loop until the URL is added to the title or timeout at 10 seconds
		WinGetTitle, CurrChromeURL, ahk_class Chrome_WidgetWin_1
		if (instr(CurrChromeURL, "|-|",0) or A_Now >= StopLoopAt){
			break
		}
		sleep, 200
	}
	if errorlevel
		return
	CurrChromeURL := RegExReplace(CurrChromeURL, "i).*\|\-\| (.*) \- Google Chrome", "$1")
	return %CurrChromeURL%
}

As i mentioned - this is obviously not anywhere near as refined as Atnbueno's amazing method.



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

Hello again.

 

Slightly improved version in the OP:
- Faster in Chromium browsers: After the first use, successive queries are instantaneous (faster than DDE!) Thanks to XeroByte for the nudge ;-)
- Improved error messages in the hotkey example
- Tested without problems in all AutoHotkey versions (U32, A32, U64) and also in Windows 8.1


Regards,
Antonio

Kudos
  • Members
  • 39 posts
  • Last active: Sep 27 2015 09:06 AM
  • Joined: 21 Aug 2006

Hi Antonio, sorry for the delay! It's annoying that the email notifications for followed topics on this forum are all greyed out :'(

 

Anyway.. I get this message in CoolNovo 2.0.9.20: The URL couldn't be determined (Chrome_WidgetWin_1)

 

Any suggestions on how to troubleshoot? Maybe this info from AU3_Spy.exe will help:

 

>>>>>>>>>>( Window Title & Class )<<<<<<<<<<<
Get the URL of the current (active) browser tab - Scripts - AutoHotkey Community - CoolNovo
ahk_class Chrome_WidgetWin_1
 
>>>>>>>>>>>>( Mouse Position )<<<<<<<<<<<<<
On Screen: 1533, 578  (less often used)
In Active Window: 1541, 586
 
>>>>>>>>>( Now Under Mouse Cursor )<<<<<<<<
ClassNN: Chrome_RenderWidgetHostHWND1
Text:
Color: 0xF0F0F0  (Blue=F0 Green=F0 Red=F0)
 
>>>>>>>>>>( Active Window Position )<<<<<<<<<<
left: -8     top: -8     width: 1839     height: 1096
 
>>>>>>>>>>>( Status Bar Text )<<<<<<<<<<
 
>>>>>>>>>>>( Visible Window Text )<<<<<<<<<<<
Get the URL of the current (active) browser tab - Scripts - AutoHotkey Community
 
>>>>>>>>>>>( Hidden Window Text )<<<<<<<<<<<
b
 
>>>>( TitleMatchMode=slow Visible Text )<<<<
www.autohotkey.com/board/topic/111114-get-the-url-of-the-current-active-browser-tab/?p=654926
Google
 
>>>>( TitleMatchMode=slow Hidden Text )<<<<
 
Thanks!! :)


Kudos
  • Members
  • 39 posts
  • Last active: Sep 27 2015 09:06 AM
  • Joined: 21 Aug 2006

The below function call is returning a blank value to accWindow :-(

accWindow := Acc_ObjectFromWindow(nWindow)

 

So I guess the DllCall in Acc_ObjectFromWindow is maybe failing..? Unfortunately I'm not skilled enough to know much more!



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

Hello again.

 

Any suggestions on how to troubleshoot? Maybe this info from AU3_Spy.exe will help: [...]

 

Not with Window Spy, but I just gave it another look to CoolNovo with AccViewer.ahk and apparently a CoolNovo window is a window inside a window, and my script looks for the url in the outside one :/

 

If you want you can check this with the List command of WinGet (you'll get a "2" or higher even when you see just one CoolNovo window, and the URL can only be found in the second one, not the first one as in all the other Chromium-based browsers):

#i::
	WinGetClass, sClass, A
	WinGet, aList, List, % "ahk_class " sClass
	MsgBox, % aList "`n" aList1 "`n" aList2
Return

I'll give a try to tweak the script for this case, but I can't promise anything.

 

EDIT: Wow, that was easy. I've updated the OP script to support CoolNovo B)


Regards,
Antonio

Kudos
  • Members
  • 39 posts
  • Last active: Sep 27 2015 09:06 AM
  • Joined: 21 Aug 2006

Wow! Thank you so much!!  :D  :D  B)



mhe
  • Members
  • 40 posts
  • Last active: Dec 04 2015 10:29 PM
  • Joined: 18 Oct 2007

Thanks i'll probably use this some time, i was looking for it in the past for some script but i never found a good solution.

 

Another thing that is problematic is copying the url that is under the mouse cursor, with chrome at least.