Firefox/Chrome, get tab names/focus tab

Post your working scripts, libraries and tools
User avatar
jeeswg
Posts: 4504
Joined: 19 Dec 2016, 01:58
Location: UK

Firefox/Chrome, get tab names/focus tab

16 Jan 2017, 04:01

[EDIT:][For updated scripts see below or click url]
Firefox/Chrome, get tab names/focus tab - AutoHotkey Community
https://autohotkey.com/boards/viewtopic.php?f=6&t=26947&p=139114#p139114

==================================================

Why has nobody updated the Firefox get tab names/set active tab functions(/scripts),
or made equivalent functions for Chrome?
Surely it's quite easy for the experts here?
And Firefox and Chrome are very common so there would be
an immediate and obvious demand?

Well, I think I've managed to do it ...

JEE_FirefoxGetTabNames(hWnd, vSep="`n")
JEE_FirefoxFocusTabByNum(hWnd, vNum)
JEE_FirefoxFocusTabByName(hWnd, vTitle, vNum=1)
JEE_ChromeGetTabNames(hWnd, vSep="`n")
JEE_ChromeFocusTabByNum(hWnd, vNum)
JEE_ChromeFocusTabByName(hWnd, vTitle, vNum=1)

Note: the functions need Acc:
Acc library (MSAA) and AccViewer download links - AutoHotkey Community
https://autohotkey.com/boards/viewtopic.php?f=6&t=26201

Working example script:
autohotkey - Using AHK to activate specific tabs in chrome or firefox - Stack Overflow
http://stackoverflow.com/questions/41478085/using-ahk-to-activate-specific-tabs-in-chrome-or-firefox

Mozilla Firefox

Code: [Select all] [Expand] [Download] GeSHi © Codebox Plus



Google Chrome

Code: [Select all] [Expand] [Download] GeSHi © Codebox Plus



Note: To get the url for the active tab:
Get the URL of the current (active) browser tab - AutoHotkey Community
https://autohotkey.com/boards/viewtopic.php?t=3702

Note: I don't have any code for getting the urls from tabs in general.

Note: These sorts of functions can easily break in future, and
so will need amending.

Do post any issues or concerns.
Thanks for reading.
Last edited by jeeswg on 24 Mar 2017, 17:58, edited 2 times in total.
sleepyswallow
Posts: 8
Joined: 04 Jan 2017, 18:56

Re: Firefox/Chrome, get tab names/focus tab

16 Jan 2017, 17:39

thanks so much, trying this now!!
User avatar
jeeswg
Posts: 4504
Joined: 19 Dec 2016, 01:58
Location: UK

Re: Firefox/Chrome, get tab names/focus tab

17 Jan 2017, 19:54

Btw the Firefox functions look for the words 'Browser tabs', so it would be interesting to know whether this has to be changed for non-English users, and if so, I'll include a warning. Cheers.
User avatar
Drugwash
Posts: 560
Joined: 29 May 2014, 21:07
Location: Ploieşti, Romania

Re: Firefox/Chrome, get tab names/focus tab

19 Jan 2017, 09:02

Can you elaborate where "Browser tabs" text should be retrieved from? I've just tried this with Pale Moon 25.8.1 and no joy.
Also, that Acc Viewer I tried to use on the Pale Moon window keeps the CPU at 100% usage so something's not right there.
Tested on XP-SP3, AHK 1.1.24.04 Unicode.

Oh and the correct link to StackOverflow would be: link
I've deleted my CloudMe account because of GDPR - the now legal base for privacy invasion and data theft.
User avatar
jeeswg
Posts: 4504
Joined: 19 Dec 2016, 01:58
Location: UK

Re: Firefox/Chrome, get tab names/focus tab

19 Jan 2017, 11:16

AFAIK Pale Moon is not the same thing as Mozilla Firefox, so there is no reason to expect the function to work with Pale Moon. Btw what class does Pale Moon have? For me Firefox has the class 'MozillaWindowClass'.

I always present links as 'title CRLF url'. Because urls can get corrupted, and titles can help to find websites when urls are changed. Also, titles can be found in search results.

Potentially, you could use AccViewer to discover a way to do this is Pale Moon, using my functions as a guide, and using the object hierarchy in AccViewer, however there were one or two complications I came across when doing this for Firefox/Chrome versus many other programs.
User avatar
Drugwash
Posts: 560
Joined: 29 May 2014, 21:07
Location: Ploieşti, Romania

Re: Firefox/Chrome, get tab names/focus tab

19 Jan 2017, 11:59

Pale Moon has the very same class as Firefox. They share same codebase.
20170119183047a.png
20170119183047a.png (136.14 KiB) Viewed 4506 times


The link in first post is incomplete, that's what I meant. Or at least it looks like that in my browser:
2017-01-19_18.29.32.png
2017-01-19_18.29.32.png (4.24 KiB) Viewed 4506 times


Played around a little more with Acc Viewer, its usage is not very intuitive. Here's the output:
20170119185334-crop.png
20170119185334-crop.png (32.4 KiB) Viewed 4506 times


I put a few OutputDebug commands in

Code: [Select all] [Download] GeSHi © Codebox Plus

JEE_FirefoxGetTabNames()
and it's getting a value of zero for oAcc.accChildCount when calling

Code: [Select all] [Download] GeSHi © Codebox Plus

Acc_Get("Object", "4", 0, "ahk_id " hWnd)
. However I get a final result with a string called "System" (there is no such tab) when calling

Code: [Select all] [Download] GeSHi © Codebox Plus

Acc_Get("Object", "1", 0, "ahk_id " hWnd)
- that is with a value of one instead of four as second parameter. But I have no idea what that is, all this object encapsulation and abstractisation is irritating because user has no control over the inner working.

Are there any more details you could share, please?
I've deleted my CloudMe account because of GDPR - the now legal base for privacy invasion and data theft.
User avatar
jeeswg
Posts: 4504
Joined: 19 Dec 2016, 01:58
Location: UK

Re: Firefox/Chrome, get tab names/focus tab

19 Jan 2017, 12:18

Thanks for the notification about the link, I've fixed it now.

When investigating Firefox/Chrome.
I used AccViewer to investigate the hierarchies from the tab button up.
I also copied AccViewer and made two replacements,
to help investigate the browsers' hierarchies from the top hWnd down:

Code: [Select all] [Expand] [Download] GeSHi © Codebox Plus



Hope that helps.

{EDIT:]
Also, try things like this:

Code: [Select all] [Expand] [Download] GeSHi © Codebox Plus

User avatar
Nextron
Posts: 1141
Joined: 01 Oct 2013, 08:23
Location: Netherlands OS: Win7 x64 AHK: Unicode x32

Re: Firefox/Chrome, get tab names/focus tab

19 Jan 2017, 12:38

Drugwash wrote:Pale Moon has the very same class as Firefox. They share same codebase.
But one of the differences, is that Pale Moon removed accessibility features, required by ACC:
Accessibility features. Most people don't have a need for specialized accessibility features for custom input or display devices. This cuts down on the input complexity, and increases speed, but will, obviously, not be suitable for people who need these features.

Also, that's a lot of pink! :shock:
The more I know:
The more I know,
I know nothing.
User avatar
Drugwash
Posts: 560
Joined: 29 May 2014, 21:07
Location: Ploieşti, Romania

Re: Firefox/Chrome, get tab names/focus tab

19 Jan 2017, 12:56

Thank you Nextron, that explains it.
Thank you for the help jeeswg, I'll let this issue rest.

As for the pink, I guess there's something wrong with my head: I can't stand color green. Besides, the computer is the only place where I can actually see la vie en rose.
I've deleted my CloudMe account because of GDPR - the now legal base for privacy invasion and data theft.
Rangnarok

Re: Firefox/Chrome, get tab names/focus tab

24 Mar 2017, 11:11

Hi Jeeswg,

I am trying to test your function to get tab name and number to use for another purpose. I am testing with the working example you posted on overstack, but encountered this error: http://imgur.com/a/Hr6J2

Could you have a look and see where i got it wrong please?

Thank you
User avatar
jeeswg
Posts: 4504
Joined: 19 Dec 2016, 01:58
Location: UK

Re: Firefox/Chrome, get tab names/focus tab

24 Mar 2017, 16:29

I have fixed the Firefox functions and improved the Chrome functions.
I have also added JEE_FirefoxGetTabCount and JEE_ChromeGetTabCount.

JEE_FirefoxGetTabCount(hWnd)
JEE_FirefoxGetTabNames(hWnd, vSep:="`n")
JEE_FirefoxFocusTabByNum(hWnd, vNum)
JEE_FirefoxFocusTabByName(hWnd, vTitle, vNum:=1)
JEE_ChromeGetTabCount(hWnd)
JEE_ChromeGetTabNames(hWnd, vSep:="`n")
JEE_ChromeFocusTabByNum(hWnd, vNum)
JEE_ChromeFocusTabByName(hWnd, vTitle, vNum:=1)

Note: the functions need Acc:
Acc library (MSAA) and AccViewer download links - AutoHotkey Community
https://autohotkey.com/boards/viewtopic.php?f=6&t=26201

==================================================

Updated Mozilla Firefox functions:

Code: [Select all] [Expand] [Download] GeSHi © Codebox Plus



Updated Google Chrome functions:

Code: [Select all] [Expand] [Download] GeSHi © Codebox Plus



A script I used to test whether the Firefox/Chrome functions were working or not:

Code: [Select all] [Expand] [Download] GeSHi © Codebox Plus



A test script, and details, regarding the Firefox problem and possible solutions:

Code: [Select all] [Expand] [Download] GeSHi © Codebox Plus

Last edited by jeeswg on 14 Mar 2018, 18:16, edited 1 time in total.
Desiet

Re: Firefox/Chrome, get tab names/focus tab

28 Nov 2017, 06:08

Cannot get data to show up

Using Chrome 61

Code: [Select all] [Expand] [Download] GeSHi © Codebox Plus

User avatar
jeeswg
Posts: 4504
Joined: 19 Dec 2016, 01:58
Location: UK

Re: Firefox/Chrome, get tab names/focus tab

28 Nov 2017, 17:29

- I tested the 4 Chrome functions just now, on Chrome v62, Windows 7, and they are still working.
- Did any of the 4 functions work for you?
- You can use AccViewer to see if you can retrieve the text:
Acc library (MSAA) and AccViewer download links - AutoHotkey Community
https://autohotkey.com/boards/viewtopic.php?f=6&t=26201
- And if you are able to retrieve the text, there is some advice here, which may make it possible for you to fix the functions to work on your PC, and then you could report back to say what you changed.
Acc: get text from all window/control elements - AutoHotkey Community
https://autohotkey.com/boards/viewtopic.php?f=6&t=40615

[EDIT:] I tested the 4 Firefox functions, on Firefox v57, and they are still working also.
Desiet

Re: Firefox/Chrome, get tab names/focus tab

28 Nov 2017, 19:11

jeeswg wrote:- I tested the 4 Chrome functions just now, on Chrome v62, Windows 7, and they are still working.
- Did any of the 4 functions work for you?
- You can use AccViewer to see if you can retrieve the text:
Acc library (MSAA) and AccViewer download links - AutoHotkey Community
https://autohotkey.com/boards/viewtopic.php?f=6&t=26201
- And if you are able to retrieve the text, there is some advice here, which may make it possible for you to fix the functions to work on your PC, and then you could report back to say what you changed.
Acc: get text from all window/control elements - AutoHotkey Community
https://autohotkey.com/boards/viewtopic.php?f=6&t=40615

[EDIT:] I tested the 4 Firefox functions, on Firefox v57, and they are still working also.

it worked very well at the end, I went to the irc room and tidbit helped me call the function correctly

thanks!
Haai Henkie
Posts: 1
Joined: 06 Jun 2018, 17:24
GitHub: HaaiHenkie

Re: Firefox/Chrome, get tab names/focus tab

09 Jun 2018, 15:20

Hello Jeesgw,

Thank you for the Firefox/Chrome tab functions.

I also wanted to activate a specific tab, but the example at StackOverflow did not suit my needs. In the hope it is of use to other people I would like to share my use case and script.

I have an AutoHotkey.ahk that defines several hotkeys and active words for starting up programs or Web pages. I wanted to be able to activate the Chrome tab with Evernote if present, else open a new tab with Evernote. This is what I added to AutoHotkey.ahk:

Code: [Select all] [Expand] [Download] (Evernote.ahk)GeSHi © Codebox Plus



Cheers,

Haai Henkie

Return to “Scripts and Functions”

Who is online

Users browsing this forum: arcticir and 16 guests