chrome.runtime.sendMessage not triggering any event listeners.

1,041 views
Skip to first unread message

Joey Takeout

unread,
Aug 26, 2019, 4:27:08 PM8/26/19
to Chromium Extensions
Hello,

I can try to share code, but the problem is very simple and confusingly so.

I have three instances of chrome.runtime.sendMessage and corresponding listeners.

(1) content script (works)
(1) loaded background script persistent (works)
(1) background.js persistent (broken)

The first two (content script & background script) work perfectly fine. I can send and receive messages no problem.

The third, in background.js, runs, loads it callback, but does not trigger any of my chrome.runtime.OnMessage listeners.

Is there a limit to how many messages can be instantiated in an app? I am using the latest & greatest of everything and manifest v2.

Thank you.

wOxxOm

unread,
Aug 27, 2019, 10:12:13 AM8/27/19
to Chromium Extensions
There is no such limit. Assuming there's no typo and you actually have onMessage, not OnMessage, something's wrong here so it's best you actually share the code. Here's why. There is only one background page which may include any amount of background scripts but all of them will be running in one page so it's unclear what you're actually doing and I've seen many people trying to load background.js where it won't be a background script like in content_scripts section or in the popup page. If you try to send messages within the same page (between two background scripts) it won't work and you'll need to invoke functions directly or use any other intra-page communication. Extension messaging is for communication across different pages/frames/tabs.
Message has been deleted

Joey Takeout

unread,
Aug 28, 2019, 11:45:45 AM8/28/19
to Chromium Extensions
This is the conclusion I came to after loads of testing.

I was unable to sendMessage within the background environment. It would have been nice to have this documented somewhere, but this is the life of a developer :)

Thank you for your replay.
Reply all
Reply to author
Forward
0 new messages