I have a script that injects a js file in each tab via
chrome.scripting.executeScript({, world: 'MAIN'})
I do that as i want to access variables of the loaded pages.
In this injected code i want to send a message to background via
chrome.runtime.sendMessage()
though in the page console i get the error:
Uncaught TypeError: Cannot read properties of undefined (reading 'sendMessage')
manifest.json (shrinked)
{
   "manifest_version": 3,
   "background": {
      "service_worker": "background.js",
      "type": "module"
   },
   "permissions": [
      "scripting"
   ]
}
background.js
chrome.scripting.executeScript({
   target: {tabId: tabId},
   files: [
      './js/asdf.js'
   ],
   world: 'MAIN'
}).then()
./js/asdf.js
console.log("asdfasdf"); # is printed
chrome.runtime.sendMessage({action: '...'}).then()
As soon as i do not run the script with world 'MAIN' i can access the method 'sendMessage'.
How can i send infos from a script injected into world 'MAIN' to the background? :)
