I'm trying to have my background.js receive information from my event.js (they are both running as background scripts) or at least allow background.js to use a function from event.js.
Why do I want to do this:
I have set up my code so that background.js handles the main tasks.
My content-scripts need saved information now and then from chrome.storage so they need to send a message to a background page.
In order to keep the code organized, I create another background page called event.js with chrome.runtime.onMessage listener and all the functions for doing the requested tasks coming from the content scripts.
Then I realize that background.js also needs to do some of those same functions, so in order to not duplicate the code, I have background.js use chrome.runtime.sendMessage to event.js.
The expected result is that event.js communicates with background.js as successfully as the content-scripts do.
The actual result is that the event.js never receives any messages from background.js.
I've read the documentation on background pages and on message passing trying to find the answer or a hint.
Is there some reason these two pages cannot communicate through messagePassing? If so, how can I successfully pass information or functions between these two pages?
requireif you use it.event.jsfunction frombackground.js, it says that function is not defined and it appears that it's attempting to invoke it beforeevent.jsloads.location.reload()to quickly reload the background page so it'll trigger breakpoints you've set and you'll see what happens when it loads.<script src="foo"></script>