I have written a GreaseMonkey (javascript) userscript that runs in a browser (Firefox) tab directed at www.site1.com/stuff
. Another tab is directed at www.site1.com
(without the stuff
), and is not a child window of the first (e.g., was not opened through the userscript running on the first tab). The userscript runs (independently?) on both tabs.
I would like the userscript execution on the first browser tab to pass a string variable to the second browser tab. While GM_setValue
and GM_getValue
work well for storage/retrieval within a single userscript, that storage area does not seem to be accessible to the other execution of the userscript. localStorage
suffers the same failure. For an explicit example:
When the userscript detects that it is running on
www.site1.com/stuff
, it places a value into storage:GM_setValue('parValue', 'aaabbbccc');
After the first tab is fully loaded and has ample time to place this value into storage, the second tab is opened manually. When the userscript detects that this second tab is running on
www.site1.com
(withoutstuff
), the code tries to retrieve the value:var parVal = GM_getValue('parValue')
. In my userscript, parVal would have anull
value; each userscript execution appears to use different storage areas.
How do I achieve this seemingly simple task of getting both executions of this same userscript to safe/retrieve from a common storage area under the following constraints:
- The
stuff
at the end of the URL of the first tab can change at-will by the user (writing separate userscripts tailored for every conceivablestuff
possibility would be impossible). - The tabs will never have a parent/child relationship, as they were generated independently (technically, the second tab is a grandchild of the first tab, but I have no idea of what the window names of the 2 tabs are or how to reference them in code).
- using javascript running in GreaseMonkey userscript
Is there some kind of global, cross-tab storage area that can be used, that could be implemented in a GreaseMonkey userscript? In theory, should GM_setValue
be applicable to this situation? I've spent substantial time poring over the answers to the following related SO questions, but was unable to find a solution that works for the above set of conditions and/or can be implemented into a GreaseMonkey userscript: Communication between tabs or windows, JavaScript: sharing data between tabs, https://superuser.com/questions/1005448/can-a-greasemonkey-script-know-whats-been-loaded-into-another-tab, Sending a message to all open windows/tabs using JavaScript,