Get the URL of the current (active) browser tab

Post your working scripts, libraries and tools
User avatar
rommmcek
Posts: 1218
Joined: 15 Aug 2014, 15:18

Re: Get the URL of the current (active) browser tab

09 Dec 2020, 03:01

@tpitera: You probably don't use it correctly! Try:
Spoiler
Haswell
Posts: 68
Joined: 21 Feb 2016, 17:11

Re: Get the URL of the current (active) browser tab

20 Dec 2020, 09:19

rommmcek wrote:
09 Dec 2020, 03:01
@tpitera: You probably don't use it correctly!
Hi rommmcek.
Thanks for your solution.
I use your code in Firefox but it looks unreliable.
Sometimes it works quite perfect but sometimes it gives me URL of a previously closed tab.
Do you notice the issue?
I failed to figure out how to fix it.
I suppose the issue is presented with Chrome too.
Focusing our efforts on non-productive and non-creative endeavours wastes lives as surely as war.
Jacque Fresco / The best that money can't buy
User avatar
rommmcek
Posts: 1218
Joined: 15 Aug 2014, 15:18

Re: Get the URL of the current (active) browser tab

20 Dec 2020, 12:00

[Edit]: I rarely use FF and Chrome. So I didn't notice such issue lately, but I noticed it in IE long time ago under specific conditions. Now I analysed it a bit closer and yeah, under harsh conditions FF gives terrible results and Chrome not much better either.
Here is my attempt tested on IE, FF (not tested on Pale Moon, but eager for feedback) and Chromium based browsers (Chrome, Edge, Vivaldi..).
Attachments
GetAccData 5.55.ahk
(3.05 KiB) Downloaded 89 times
Last edited by rommmcek on 14 Jan 2021, 11:52, edited 10 times in total.
User avatar
rommmcek
Posts: 1218
Joined: 15 Aug 2014, 15:18

Re: Get the URL of the current (active) browser tab

05 Jan 2021, 10:36

GetAccData() v5.55 - function to retrieve Title and Url of the desired browser tab
Spoiler
P.s.: Sorry for that much quotes in the Spoiler, but I want to get as much feed back as possible!
Last edited by rommmcek on 14 Jan 2021, 11:55, edited 15 times in total.
burque505
Posts: 1446
Joined: 22 Jan 2017, 19:37

Re: Get the URL of the current (active) browser tab

05 Jan 2021, 12:10

@rommmcek, thank for this, should come in very handy. I just tried it with 5 tabs open in Firefox 84.0.1 64-bit and 7 tabs open in Chrome Version 87.0.4280.88 (Official Build) (64-bit). I set a hotkey as shown below, randomly went from tab to tab, switching browsers randomly, not a single failure or incorrectly reported tab. Win7 SP1 64-bit.

Code: Select all

^!#f::
GetAccData() ; parameter "WinTitle" - Ahk like syntax e.g. "A" (default), "ahk_class IEFrame", "ahk_exe google.exe", etc.
MsgBox % accData.1 "`n`n" accData.2
Return
Regards,
burque505
User avatar
rommmcek
Posts: 1218
Joined: 15 Aug 2014, 15:18

Re: Get the URL of the current (active) browser tab

05 Jan 2021, 14:02

Good to hear it! Yeah, switching Tabs is crucial and I tested closing some of them randomly (which causes switching too). Now it came to me it should be tested with opening new tabs likewise, but the true test will be, when people will be using it for the prolonged period of time under all sorts of unpredictable conditions!

P.s.: After posting the function and signing out (in IE) I got some weird results (again in IE), but then I couldn't reproduce the issue, so I don't know the real reason...

P.p.s.: Limitation in Chrom - Search box may not be opened (Ctrl + f as native Chrom shortcut).
[Edit]: Simple workaround included in the updated code above!
Dinarid
Posts: 2
Joined: 11 Jan 2021, 18:38

Re: Get the URL of the current (active) browser tab

11 Jan 2021, 18:49

My question is only tangentially related to this, and I'm not sure if there's a better subforum for it -- if there is one, I don't mind if my post is moved there, of course.

I'm trying to use this to copy the URL to the clipboard, and it works fine, but the resulting URL always has quote marks (as in "www.url.com"). I'd like to remove those quote marks, but I have no idea how (I've tried removing a pair of quote marks in the script, but then AHK always returns " sURL " instead of the actual URL). Could anyone help?

Here's my code:

Code: Select all

#c::
	nTime := A_TickCount
	sURL := GetActiveBrowserURL()
	WinGetClass, sClass, A
	If (sURL != "")
		Clipboard:= % """" sURL """"
	Else If sClass In % ModernBrowsers "," LegacyBrowsers
		MsgBox, % "The URL couldn't be determined (" sClass ")"
	Else
		MsgBox, % "Not a browser or browser not supported (" sClass ")"
Return
gregster
Posts: 5795
Joined: 30 Sep 2013, 06:48

Re: Get the URL of the current (active) browser tab

11 Jan 2021, 19:21

Dinarid wrote:
11 Jan 2021, 18:49
My question is only tangentially related to this, and I'm not sure if there's a better subforum for it -- if there is one, I don't mind if my post is moved there, of course.

I'm trying to use this to copy the URL to the clipboard, and it works fine, but the resulting URL always has quote marks (as in "www.url.com"). I'd like to remove those quote marks, but I have no idea how (I've tried removing a pair of quote marks in the script, but then AHK always returns " sURL " instead of the actual URL). Could anyone help?
[...]

Code: Select all

		Clipboard:= % """" sURL """"
That would generally fit better into 'Ask For Help', imo (and we might move it). But I don't understand your use of quote marks in this case.
Why not just

Code: Select all

Clipboard := sURL
if I understand you correctly?!
A look into expressions might be beneficial.
Dinarid
Posts: 2
Joined: 11 Jan 2021, 18:38

Re: Get the URL of the current (active) browser tab

11 Jan 2021, 20:21

Thank you! That solved it. I realize it was a basic question, I just started using AHK a few days ago and I'm still learning.

Return to “Scripts and Functions”

Who is online

Users browsing this forum: No registered users and 19 guests