Disabling sync of enabled scripts over multiple browser windows

Post Reply
gorantoth
Posts: 3
Joined: 09.02.18 20:02:51

Disabling sync of enabled scripts over multiple browser windows

Post by gorantoth » 09.02.18 20:47:42

Did some searching, could not find something like this anywhere, so apologies if this has been asked before.

I appreciate that in a single Chrome window with multiple tabs, that I can enable and disable scripts globally for all tabs within that window. However, when I open a second Chrome window, usually by peeling a tab out to create a new window the scripts enable/disable across windows too. So if I enable a script in Window A, it is also enabled in Window B.

I have a site where I need to be able to run two different scripts on the same page. The two scripts interfere with each other if run simultaneously as they both navigate to different pages from a common page, and because of a third script, will both eventually return to the common page. The best idea I've come up with so far is to use different windows so that one script will operate within one instance, and a second in the other, with common scripts also operating. But because of the synchronization of which scripts are enabled even between different windows, it doesn't work and I eventually see one script taking precedence, causing both windows to eventually perform the same task.

I cannot use two different browsers. Both windows need to be Chrome as using a different browser entirely causes the other one to log out of the site.

User avatar
derjanb
Site Admin
Posts: 2368
Joined: 20.01.06 02:16:15
Contact:

Re: Disabling sync of enabled scripts over multiple browser windows

Post by derjanb » 09.02.18 21:01:23

You can use something like this to make a script run only at one tab: viewtopic.php?f=21&t=1000#p3655
ImageIf you like what I'm doing, please consider a donation here. Image

gorantoth
Posts: 3
Joined: 09.02.18 20:02:51

Re: Disabling sync of enabled scripts over multiple browser windows

Post by gorantoth » 09.02.18 21:42:06

From what I read of that thread, it looks like it allows a script to only run in a single tab at a time. What happens when the script completes? Can another tab then execute that script?

The problem is that the two scripts I need to isolate are fairly small and run only briefly on the one page before navigating away to where another script takes over. Due to the async nature of the tasks being run, there's no guarantee that both tabs will return to the same page at the same time for a temporary lock to be effective.

Here is the extent of both scripts that run on this one page... the only difference is that the second script clicks a different button. Due to the complexity of the other scripts involved in the pages that these buttons go to, I can't lock them to a single tab, since it is possible for them to be triggered through subframes on other tabs.

Code: Select all

button = document.getElementsByClassName('btn1');
if(button.length > 0)
{
    button[0].click();
}

User avatar
derjanb
Site Admin
Posts: 2368
Joined: 20.01.06 02:16:15
Contact:

Re: Disabling sync of enabled scripts over multiple browser windows

Post by derjanb » 09.02.18 21:50:07

This all sounds quite complex and I don't have a perfect solution for you. So all I can say is you can make scripts communicate and therefore also synchronize them using GM_getValue, GM_setValue and (to avoid polling) GM_addValueChangeListener.
ImageIf you like what I'm doing, please consider a donation here. Image

gorantoth
Posts: 3
Joined: 09.02.18 20:02:51

Re: Disabling sync of enabled scripts over multiple browser windows

Post by gorantoth » 09.02.18 23:18:48

I might be able to use that to alternate between the two scripts. It wouldn't be a great solution, but it would be a start. Where each one sets a value when complete to let the other script know it is allowed to execute next time that page is encountered. It would at least force the two scripts to alternate execution. Which is a better situation than I have now.

That could also allow me to combine these simple small scripts into a larger management script that "remembers" which path was last taken....

ie if value 1 then go path A and set value 2, if value 2 then go path B and set value 1....

Thanks. I'll have to play with that and see if it will work.

Post Reply