[Project_owners] Communicating between browser instances

Steven D Tine stevetine at yahoo.com
Sat Jan 14 20:13:14 EST 2006


I'm going to apologize up front if the question I'm
asking is very basic but I'm new to extension
development and JavaScript.

It appears that each instance of the browser (e.g.
when I choose 'File->New Window' or ctrl-n, a new
browser window opens) has a unique copy of the
extension code running it.  So, for example, the
SwitchProxy extension (not my extension, but an easier
example to describe than my extension) has an icon in
the status bar.  When you click the icon, it
alternates between red (no proxy configured) and green
(proxy configured).  The problem is that when you have
two browser windows open, the status bar is not in
sync between the two windows.  By that I mean, when
you click the icon in one window, the other window is
not updated and the instance of the code in that
window does not know that a change happened, so one
window shows red and one shows green but obviously
there is only one proxy setting for both windows so
one window is wrong.  Is there a way for the code in
the first instance to notify the code in the other
window instances that a change was requested and
completed?

And to clarify my question, I don't just want to
update the icon, but actually somehow notify my code
in the other instance to update some state and then
update the icon.

I searched the archives for this mailing list and I
found Eric Jung posted this code:
>   var urls = new Array();
>   var wm =
>    
Components.classes["@mozilla.org/appshell/window-mediator;1"]
>    
.getService(Components.interfaces.nsIWindowMediator);
>   var browserEnumerator =
wm.getEnumerator("navigator:browser");
> 
>   while (browserEnumerator.hasMoreElements()) {
>     var browserInstance =
>      
browserEnumerator.getNext().document.getElementById("content");
>     // Check each tab of this browser instance
>     var numTabs =
browserInstance.mPanelContainer.childNodes.length;
>     for (var index=0; index<numTabs; index++) {
>       var currentTab =
browserInstance.getBrowserAtIndex(index);
>       urls.push(currentTab.currentURI.spec);
>     }
>   }

Which I think I might be able to use to get access to
the status bar item in the other windows but I'm not
sure how to notify my code in the other browser
instances to get the underlying code in sync, not just
the icon.

Thanks in advance,
Steve
P.S. Jorge, this post isn't spam...just kidding :-) 

__________________________________________________
Do You Yahoo!?
Tired of spam?  Yahoo! Mail has the best spam protection around 
http://mail.yahoo.com 


More information about the Project_owners mailing list