Good question..

On Fri, Dec 4, 2009 at 8:19 PM, nachumk <[email protected]> wrote:
> function createExtensionInMainPage() {
>  this.port = chrome.extension.connect();
>  this.port.onMessage = extOnMessage;
>
>  this.port.postMessage('ready'); // *** I don't know if the background
> page has hooked up it's onMessage!
> }

The system promises to run background page initialization code before
attempting to deliver any messages from content scripts, so this is
fine.

> function extOnMessage(msg) {
> }
>
> function createBackgroundPage() {
>  chrome.extension.onConnect.addListener(backOnConnect);
> }
>
> function backOnConnect(port) {
>  port.onMessage.addListener(backOnMessage);
>
>  port.postMessage('alternateReady'); // *** I also don't know if the
> main page has hooked up it's onMessage!
> }

JavaScript is not multithreaded, it is event driven.

So:

port.sendMessage(...);
port.onMessage.addListener(function() {

});

You never need to worry about the other end of the connection sending
the message before the onMessage event is hooked, that is impossible.
All the code after sendMessage will run to completion before any
asynchronous events are delivered.

- a

--

You received this message because you are subscribed to the Google Groups 
"Chromium-extensions" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to 
[email protected].
For more options, visit this group at 
http://groups.google.com/group/chromium-extensions?hl=en.


Reply via email to