Fr33b0w

[(UN)SOLVED] Count how many tabs are open in firefox

19 posts in this topic

#1 ·  Posted (edited)

Is there any way that autoit can detect how many TABs are open in firefox browser? Or any other workaround method to do so? Help would be gladly appreciated.

Edited by Fr33b0w

Share this post


Link to post
Share on other sites



#2 ·  Posted

What have you tried so far? Did you check the Firefox UDF?

1 person likes this

My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2017-04-18 - Version 1.4.8.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (NEW 2017-02-27 - Version 1.3.1.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2015-04-01 - Version 0.4.0.0) - Download - General Help & Support - Example Scripts
Excel - Example Scripts - Wiki
Word - Wiki
PowerPoint (2015-06-06 - Version 0.0.5.0) - Download - General Help & Support

Tutorials:
ADO - Wiki

 

Share this post


Link to post
Share on other sites

#3 ·  Posted

This can be done with _FFGetLength.

1 person likes this

Share this post


Link to post
Share on other sites

#4 ·  Posted

A simple code like this worked:

$tabs=_FFGetLength("tabs")
If $tabs > 5 Then
Send("^{F4}")
Sleep(1000)
EndIf

Thanks Danp2 and Water! :)

Share this post


Link to post
Share on other sites

#5 ·  Posted (edited)

To be honest this isn't working. I thought it does because tabs have always been in a control and never in overflowing number. Anyone has an idea why this ain't working? Mozrepl is on. What should I try? Any suggestions?

Global Const $_FF_AU3VERSION = "0.6.0.1b-15"

Firefox 54.0.1 (32-bit)

mozRepl 1121-signed.1-signed by hyperstruct (https://github.com/bard/mozrepl/wiki)

Windows 7 ultimate SP1

Edited by Fr33b0w

Share this post


Link to post
Share on other sites

#6 ·  Posted

You'll need to provide more details. What exactly isn't working as you would expect?

Share this post


Link to post
Share on other sites

#7 ·  Posted

i basically want to limit number of open tabs in firefox so if there is more opened then (lets say) 5, I need to limit them down, as simple as it sounds and as complicated as it is when trying to code it :) . At this point I am getting "" as an answer no matter how many tabs exist in firefox...   $tabs=0

Share this post


Link to post
Share on other sites

#8 ·  Posted

It really isn't difficult. You just need to create a loop that will run until the number of tabs is within the desired range, something like this --

While _FFGetLength("tabs") > 5
    _FFTabClose('last', 'key')
WEnd

 

Share this post


Link to post
Share on other sites

#9 ·  Posted

Thanks for that but it wouldn't give me info how much tabs are open. Do you have a clue why it might be so and what should I try?

 

#Include <FF.au3>

While _FFGetLength("tabs") > 5
    _FFTabClose('last', 'key')
WEnd

[Click and drag to move]

 

Share this post


Link to post
Share on other sites

#10 ·  Posted

Not off hand. I'll have to dig into the UDF code to try to figure out why it isn't working as designed.

Share this post


Link to post
Share on other sites

#11 ·  Posted

Ok... there's nothing wrong with the UDF. You have to first establish the connection to FF. So the revised script would be --

#Include <FF.au3>

_FFConnect()

While _FFGetLength("tabs") > 5
    _FFTabClose('last', 'key')
WEnd

 

Share this post


Link to post
Share on other sites

#12 ·  Posted

If you click on a tab, and locate in the menu "Close Other Tabs" and click.

it will give you a dialog box with the number of tabs.


 

Spoiler

shoot_zpsfd329d66.png
dontbelieveeverythingyouthink_zps0e1e900

Madness is the first step to understanding...

Share this post


Link to post
Share on other sites

#13 ·  Posted (edited)

On 8/29/2017 at 2:23 AM, Somerset said:

If you click on a tab, and locate in the menu "Close Other Tabs" and click.

it will give you a dialog box with the number of tabs.

It won't give me right click menu on tabs on win7. It did before on XP but I guess upgrade or something wont work like that.

 

 

On 8/28/2017 at 7:52 PM, Danp2 said:

Ok... there's nothing wrong with the UDF. You have to first establish the connection to FF. So the revised script would be --

#Include <FF.au3>

_FFConnect()

While _FFGetLength("tabs") > 5
    _FFTabClose('last', 'key')
WEnd

 

It did showed me first time or with first run of the script but now it won't show me how much tabs are open... 

 

My code:

#Include <FF.au3>

_FFConnect()
Sleep(2000)
If _FFIsConnected() Then
$tabs=_FFGetLength("tabs")
If $tabs > 4 Then
;_FFTabClose("first")
_FFTabClose("last")
Sleep(1000)
;_FFDisConnect()
EndIf
EndIf

Is there any kind of workaround with this or anyone knows why it won't count tabs? Help again much appreciated.

Edited by Fr33b0w

Share this post


Link to post
Share on other sites

#14 ·  Posted

You had a problem in your _FFTabClose line, but otherwise looks fine to me. Try running the following in Scite and post the complete results from the output window --

#Include <FF.au3>

_FFConnect()
Sleep(2000)

If _FFIsConnected() Then
    $tabs=_FFGetLength("tabs")
    ConsoleWrite("$tabs=" & $tabs & @CRLF)

    If $tabs > 4 Then
        _FFTabClose("last", 'key')
    EndIf
EndIf

 

Share this post


Link to post
Share on other sites

#15 ·  Posted

Thanks!

_FFConnect: OS:    WIN_7 WIN32_NT 7601 Service Pack 1
_FFConnect: AutoIt:    3.3.14.2
_FFConnect: FF.au3:    0.6.0.1b-15
_FFConnect: IP:    127.0.0.1
_FFConnect: Port:    4242
_FFConnect: Delay:     2ms
_FFConnect: Socket:     536
_FFConnect: Browser:    
__FFSendJavaScripts: Sending functions to FireFox .......... done
__FFSend: try{FFau3 != null?1:0}catch(e){'_FFCmd_Err';};
__FFRecv:
_FFIsConnected ==> Socket Error: 536
>Exit code: 0    Time: 3.747

 

Share this post


Link to post
Share on other sites

#16 ·  Posted

Are you sure that you have MozRepl installed and running? Your output should look like this --

_FFConnect: OS: WIN_10 WIN32_NT 15063 
_FFConnect: AutoIt: 3.3.14.2
_FFConnect: FF.au3: 0.6.0.2b-1
_FFConnect: IP: 127.0.0.1
_FFConnect: Port:   4242
_FFConnect: Delay:  2ms
_FFConnect: Socket:     872
_FFConnect: Browser:    Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:54.0) Gecko/20100101 Firefox/54.0
__FFSendJavaScripts: Sending functions to FireFox .......... done
__FFSend: try{FFau3 != null?1:0}catch(e){'_FFCmd_Err';};
__FFRecv: 1
__FFSend: try{gBrowser.tabContainer.childNodes.length}catch(e){'_FFCmd_Err';};
__FFRecv: 16
$tabs=16
__FFSend: try{gBrowser.tabContainer.childNodes.length}catch(e){'_FFCmd_Err';};
__FFRecv: 16
__FFSend: try{gBrowser.removeTab(gBrowser.mTabs[gBrowser.tabContainer.childNodes.length-1]);gBrowser.tabContainer.childNodes.length}catch(e){'_FFCmd_Err';};
__FFRecv: 15
+>10:50:44 AutoIt3.exe ended.rc:0
+>10:50:44 AutoIt3Wrapper Finished.

Also, what version of Firefox are you using? If you are using FF 55 or greater, then MozRepl is no longer working and that would explain your issues.

1 person likes this

Share this post


Link to post
Share on other sites

#17 ·  Posted

You are right...  It upgraded while my son was using the PC. Its 55.0.3 (32-bit) now. :(   Thanks for Your help!

Share this post


Link to post
Share on other sites

#19 ·  Posted

I have temp solved it with addon for FF (Window and Tab Limiter) because I needed limited tabs to be opened due to FF crash. This uiautomation really looks good so I will check it out. Thanks!

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!


Register a new account

Sign in

Already have an account? Sign in here.


Sign In Now