Search code examples
javascriptgreasemonkeytampermonkeysetvaluegetvalue

Tampermonkey, waiting for value to be set in another tab os it can be read


I have a userscript that opens another tab, where it runs too.

I use GM_setvalue and GM_getvalue to exchange a value between them.

In the main tab, I want to halt the execution of the code until the value is updated from the other tab.

My first and so far the closest try was when I added a while() loop with an empty command to check for the stored value, if it still has its default value set. My code does change the stored value in the other tab, but in the main tab the code is still stuck in the loop. For which, I do not see the reason.

Could you please help me?

Regards, polarka


Solution

  • You can Creating and triggering events in the sender tab to send a CustomEvent (when data is updated) and addEventListener in the target tab to listen for that event.