I need to connect to a background page from my extension. I believe
chrome runs the background page in a different thread from the main
page (with injected extension code), therefore how do I properly
synchronize the port connect code?
The issue that I'm trying to demonstrate exists due to the nature of
the connect. Since the port doesn't exist until the create I believe
there is a theoretical race condition.
simple example:
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!
}
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!
}
I don't know the internal architecture and therefore this might not be
a problem at all, but I'd love some feedback to assure me of this. I
also prefer to not delay the code with some type of timeout or other
event as that seems like a hack to me.
I haven't yet checked if send/onRequest functions are working yet, as
I know they previously didn't in the beta. That is a way to solve this
problem if they work but it also seems a bit hack like...
Thanx,
Nachum
--
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.