How to create a communication channel between two sites

Author: Heliomance
Message:

hrm, anyone know how to pass information from a chrome extension to a Foundry module? VTTAssets does it, so I know it’s possible, but I’m not sure how

Author: Daddi

Message:

hrm, anyone know how to pass information from a chrome extension to a Foundry module? VTTAssets does it, so I know it’s possible, but I’m not sure how
<@!231405291839684610>

Browser extensions have three kinds of scripts:
popup scripts, background scripts and content scripts.

Popup-Scripts are for the extension popup, background scripts for communication and content-scripts for everything that happens inside a tab. They have more or less full control over the webpage and can use foundries globally available objects and methods.

Author: KaKaRoTo

Message:

Your foundry module simply provides some public functions for the content-script to use / talk to.
<@!186430240493404171> also that don’t work because content scripts are in a sandbox and cannot access any API available to the actual page. They can only access the DOM itself.

The trick to that is to actually have a separate page-script that the content script will then inject into the page using a <script> tag that it adds to the page
the page script needs to be declared in the web-accessible extension manifest so it can be loaded and need to use chrome.runtime.getURL (I think) to get the url of the file so it can be injected