Chrome Extensions: simple message passing vs chrome connection -


At which point should I use Chrome connection? Is there a good reason to pass any simple message and use long-lasting connections?

Do both of these have different execution effects?

Is there any other document than two approaches?

(edit: moved to document)

sendMessage to start state , And connect anytime.

I want to send the information over and over again.

For example, there are usually user-configurable options in my extensions, and I need a way to send those options to my content script I want to pass JSON objects to my content script This object includes various user-controlled settings and possibly other states, including sendMessage and onMessage .

I also created a small library that allows to define keyboard shortcuts in the background page. How it works is simple: A content script is injected into every page, which then listens for keydown and keyup events.

When an event occurs, it uses chrome.runtime.connect to communicate with the background page. I think this is an excellent example when a long-standing connection will be more useful than many sendMessage calls.

I do not think you need anything to use them in one way or another ... You can use multiple sendMessage or just a message I can send with connect I believe this is another case of terminology and to choose which tool makes the best sense for the job.

Also keep in mind that the use of connectivity makes it easy to store individual states for each connection, while it is difficult to make TED with sendMessage .

For display ... I do not know honestly, but I expect them to be at least equal, i.e. 5 send message with approximately 5 messages being connected Send will be equal. Keep in mind that they are asynchronous, so depending on the circumstances, fluctuation in time can occur.


Comments