After setting content_scripts.world to "MAIN", how to communicate with the background page?

28 Views Asked by At

Below is manifest.json.

{
    "manifest_version": 3,
    ...
    "content_scripts": [
        {
            ...
            "world": "MAIN",
            "all_frames": true
        }
    ],
}

I set "word": "MAIN" and then due to a change in the runtime environment, chrome.runtime is undefined and I can't use the chrome.runtime.onMessage API to accept data sent from the background page.

Now when I want to send data from the background page to content_scripts what do I do?

Another question is, in the case of 'world' : 'MAIN', how do I send data from content_scripts to the background page?

The key thing to note about this is that content_scripts is already 'world: "MAIN" will not be able to access any of chrome's apis, which is a feature of setting this option. This is not a problem with normal content_scripts communicating with background pages.

0

There are 0 best solutions below