closing tab in a macro

DBG

New Member
VIP
Joined
Mar 2, 2021
Messages
12
Reaction score
0
Achievement
Hello. Maybe you can help me with this. I am running a macro that opens up three browser tabs.
I'd like to move focus to the first one (no problem with that) and then close the third tab at one point during the macro run. Is this possible? I've tried several pieces of code, but the macro seems to get stuck as if it did not know where to continue executing its code once it closes the tab.

I also have a concept question regarding the "main" tab (the one that is opened when the macro starts).
Can it be closed during macro execution (and the macro keeps running normally in other tabs) or must it be persistent during the whole time the macro is running?

Thanks for the help!!
 

opsfafsme

Well-Known Member
Rule The Universe
VIP
Joined
Jul 2, 2018
Messages
228
Reaction score
87
Website
OnlinePiercingShop.com
Achievement
 

DBG

New Member
VIP
Joined
Mar 2, 2021
Messages
12
Reaction score
0
Achievement
Thank you so much!!

Yes, I had seen, copied and tried that piece of code but I found my macros would freeeze, that is, macro execution stopped without any error messages or anything, and that "frozen" state would last until the duration allowed for the macro would be completely spent. So I thought the code was not useful anymore.

I gave it a try again after your kind reply and for some reason it decided to work. Thanks!!

The down side is that when I use that piece of code to close a tab different to the "main" or initial one, it works okay, but I also need to close that initial tab sometimes and then we go back to the freezing problem.

This is a sample of my code. The macro is running normally, with two open tabs.


TabFocus(1);
await EvaluateScript("setTimeout(function(){var ww = window.open('about:blank', '_self'); ww.close();}, 500);");
await Delay(400);
TabFocus(1);
await Delay(Random(2500,3500));
Log ("Macro runs this far");
do { //scroll
scrl = Random(10,15);
for (var i = 1; i < scrl; i++) {
await EvaluateScript("var ddE = document.documentElement; ddE.scrollTo(0, ddE.clientHeight/(Math.floor(Math.random()*3)+9) + ddE.scrollTop);");
await Delay(Random(100,200));
}


I can see in the Output Panel the log entry "Macro runs this far" but the macro does not scroll or do anything but run the timer down.
I even manually click in the open window with the mouse, move the scroll bar, etc, but there is nothing that seems able to "unfreeze" it.

Any ideas why this may be happening?

Thanks for all your help!
 

opsfafsme

Well-Known Member
Rule The Universe
VIP
Joined
Jul 2, 2018
Messages
228
Reaction score
87
Website
OnlinePiercingShop.com
Achievement
TabFocus(1);
await EvaluateScript("setTimeout(function(){var ww = window.open('about:blank', '_self'); ww.close();}, 500);");
await Delay(400);
TabFocus(1);
open tabs are numbered starting from the (1)
there is little logic in your code, you close the first (1) tab and then try to continue executing the macro in it
you need to move focus to another tab
the setTimeout function is just used to delay the closing of the current tab so that you can move the focus to another tab
I apologize for my English, I hope I explained clearly
 
Last edited:

DBG

New Member
VIP
Joined
Mar 2, 2021
Messages
12
Reaction score
0
Achievement
Hi, sorry for the delay in answering your message. You are right it works now. For some reason I thought the system would re-index the tabs after closing one and that is why I went back to tab (1). Thanks!!
 

About us

  • Our community has been around for many years and pride ourselves on offering unbiased, critical discussion among people of all different backgrounds. We are working every day to make sure our community is one of the best.

Quick Navigation

User Menu