1

Similar to this, but has more details.

  • "share"ing is expected to be done by one script.
  • "storage" is which GM_{g,s}etValue use.
  • "different websites" are those which have different origins.

My scheme now:

  • On website A, I insert an iframe of site B, and synchronize storage by postMessage.

Information I've got:

  • From this, it seems that Tampermonkey used to support share data cross-originly.
  • 2
    Simply add `@match` for both URLs (the page and the iframe) so the storage will be automatically the same, [more info](https://stackoverflow.com/a/6053388). – wOxxOm Jul 15 '21 at 16:43

1 Answers1

3

As mentioned by wOxxOm, in order for 2 domains to share data via GM storage API, the script must run on both e.g. via @match.

However, in Tampermonkey the domains will get access to the data at the time script was injected.

Update: As pointed out by wOxxOm, "Both Tampermonkey/Violentmonkey provide real-time access to the real values. They do it by propagating the change to all tabs/frames where this script instance runs."

You can also use GM_addValueChangeListener() to listen to changes to the storage.

GM_addValueChangeListener()
Adds a change listener to the storage and returns the listener ID.
'name' is the name of the observed variable.
The 'remote' argument of the callback function shows whether this value was modified from the instance of another tab (true) or within this script instance (false).
Therefore this functionality can be used by scripts of different browser tabs to communicate with each other.

Note: In Greasemonkey & FireMonkey, the asynchronous GM.getValue() would always get the current up-to-date data.

erosman
  • 7,094
  • 7
  • 27
  • 46
  • 1
    Both Tampermonkey/Violentmonkey provide real-time access to the real values. They do it by propagating the change to all tabs/frames where this script instance runs. – wOxxOm Jul 16 '21 at 19:38