Selects wrong tab sometimes

I’m using the chrome extension and I have a bookmark/shortcut to run a macro. I usually have two browser windows open(work and personal), the macro works perfectly with the exception that occasionally when I run it, instead of running in the current tab, it will run on a tab in the other window.

Just to clarify: So you have “tab A” open, but the macro runs in “tab B”?

Not quite. It’s more like, I have Window A open with tab 2 selected but when I run the macro it runs on Window B tab 1 instead(the tab it runs in isn’t always the same one or position).
I haven’t found a way to replicate it yet, but there seems to be some relationship between using the tab in window B recently and then switching to window A tab 2 and running the macro.
Actually, after typing this out I just tried a few more scenarios and it looks like it might be to do with whether you’ve done anything in the currently selected tab. It might be that selecting the tab you want to run the macro in isn’t enough, you need to have clicked a link or done something for it to be considered the active tab. Perhaps it’s just a problem with my macro.

A little more testing, a few scenarios:
Switching tabs within windowA where I’m running the macro is fine, it runs on the active tab.
If I do something on a tab in windowB then switch to windowA and run the macro, it will run on the last active tab on windowB.
If I do something on a tab in windowB then switch to windowA and change tabs before running the macro, it then runs on the active tab in windowA.

So, I think this describes the problem; switching from one window to another and then running a macro without performing an action in the active tab(either clicking a link or changing tabs) will result in the macro being run on the last active tab in the other window.