Jump to content
Fr33b0w

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

Recommended Posts

Fr33b0w

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
water

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

  • Like 1

My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2018-10-19 - Version 1.4.10.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (2018-10-31 - Version 1.3.4.1) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts
PowerPoint (2017-06-06 - Version 0.0.5.0) - Download - General Help & Support
Excel - Example Scripts - Wiki
Word - Wiki
 
Tutorials:

ADO - Wiki

 

Share this post


Link to post
Share on other sites
Fr33b0w

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
Fr33b0w

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
Fr33b0w

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
Danp2

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
Fr33b0w

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
Somerset

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

 

Share this post


Link to post
Share on other sites
Fr33b0w
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
Danp2

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
Fr33b0w

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
Danp2

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.

  • Like 1

Share this post


Link to post
Share on other sites
Fr33b0w

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
Fr33b0w

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

×