0

I'm building a chrome extension with ReactJs. I understood how content-script and background script works but, I'm not able to "share" an object/methods between the chrome extension (popup) and the current web page.

For example:

MetaMask inject a global web3 object, every page can use it and trigger the pop-up chrome extension.

Any idea?

greengo
  • 33
  • 5
  • You need to put that code into a page ` – wOxxOm Jul 22 '19 at 07:00
  • Thank you for your answer, what about if I would like to inject this object in all the websites like Metamask does? In externally_connectable the URL pattern must contain at least a second-level domain – greengo Jul 22 '19 at 10:13
  • There are no magic tricks here so you'll have to use DOM messaging, see the example I've linked. – wOxxOm Jul 22 '19 at 10:47
  • I read all the links that you provided. Are complete and well written but I'm still quite confused. If I understood correctly to receive a json from a web Page I would need: 1. An injected script 2. Send DOM messages from the injected script to the content script 3. Since I want a state persistence running Redux in the background script that receives DOM messages and saves in the chrome.storage. 4 The UI connected to the storage – greengo Jul 23 '19 at 21:15
  • Yeah it can work if in step 4 you use chrome.storage.onChanged. Or you can use sendMessage/onMessage in steps 3-4 and save to storage in step 4 if needed. – wOxxOm Jul 24 '19 at 04:28

0 Answers0