Questions and answers from the newsgroups 2006 10 27

Return to mozilla-dev-extensions


(ā†‘ top)

How to "migrate" an existing FF extension to Thunderbird?
Step 1: Add Thunderbird compatibility info to install.rdf.
Step 2: Overlay messenger.xul { instead of / as well as } browser.xul.
Step 3: Add code to fix errors that crop up now that your extension is running in Thunderbird.
Hint: Look at how the autohidestatusbar extension (which works in Firefox, Thunderbird and seaMonkey) does it.
Does any one know why radio button icon does not show in sidebars?
Many widgets work in boilerplate code from simpler sidebars, but to use radio buttons one must include the browser stylesheet.
<?xml-stylesheet href="chrome://browser/skin/browser.css" type="text/css"Ā ?>
needed for button icons
<?xml-stylesheet href="chrome://global/skin/global.css" type="text/css"?> this is the more general solution.
How to control window watcher?
Not sure that it's possible to resize and move a window immediately after it's been created, you might try waiting for it to load first.
After changed the openWindow call to
ww.openWindow(null, url, 'Title of Window', features, null);
was able to add events handlers and control the window. So it must of been an issue with using the browser XUL.
How to parse the DOM?
Is there a way to trigger screengrab by command line args?
This is a standard XPCOM component. You install/use it by putting in your extension's/application's 'components' folder:
Whether you'll be able to "call the necessary javascript" depends on what exactly you're going to call. Do you have the actual screen grabbing code? I'd start with that rather than the cmd line handler.
compreg.dat / xpti.dat contain information about registered components and interfaces. These files are written out by Firefox after the XPCOM registration process.
During the registration process, Firefox looks in a few predefined places (like app's and each extension's components folder) for files that may contain components or interfaces.
For each file that might provide components (e.g. js or binary so or dll), it tries to run its registration function, which calls back into component manager to register the components it provides (and adds them to XPCOM "categories" if needed). Each typelib (xpt) file is scanned for interfaces.
So all you need to do is to put a specially-crafted component file in one of folders Firefox searches for components and trigger the registration process (a common way to do it when developing is to delete compreg.dat). Or just create an XPI with your component in its components/ folder and install it; autoregistration happens after installing XPIs too.
There's a separate "scope" (different global object) for each "window" (which is not just windows in the window manager sense - see and for each XPCOM component.
That extension's code most likely lives in a browser.xul overlay, meaning it's is in a different scope than your cmd line handler's code. On the other hand, the handler's code is invoked early when you can't make screen shots of the page yet. So you'll probably have to find a way to defer the handling until the browser window opens.
How to get return value from modal dialog?
Here's one way to do it.
The code to open the a dialog named mydialog.xul and pass it arguments:
 var params = {inn:{name:"foo", description:"bar", enabled:true}, out:null};        
  window.openDialog("chrome://myext/chrome/mydialog.xul", "",
    "chrome, dialog, modal, resizable=yes", params).focus();
  if (params.out) {
   // user clicked ok--process changed arguments (write them to disk or whatever)
 id="theId"   title="some title"
 ondialogaccept="return onOK();"
 persist="screenX screenY width height"
 <script type="application/x-javascript" src="chrome://myext/content/mydialog.js"/>
 // xul here
function onLoad() {
 // use the arguments passed to us
 document.getElementById("name").value = window.arguments[0];
 document.getElementById("description").value = window.arguments[0].inn.description;
 document.getElementById("enabled").checked = window.arguments[0].inn.enabled;
function onOK() {
  // return the changed arguments.
  // notice if user clicks cancel, window.arguments[0].out remains null
  window.arguments[0].out = {name:document.getElementById("name").value,
  return true; 
How to update internet search RDF?
This interface appears to have several methods you can use including: void Flush ( )
Request that a data source write it's contents out to permanent storage,if applicable.
void Refresh ( PRBool blocking )
Refresh the remote datasource, re-loading its contents from the URI.
   blocking: If true, the call will block until the data source has completely reloaded. 
How to build a Turkish dictionary?
What you need is a myspell dictionary. This is the same dictionary format used by OpenOffice. I don't know whether we have any good documentation on the format, though the web probably does.
Once you have the .aff and .dic files, let the Turkish l10n team know and

they can create the extension using my dictionary-packager tool.

How to call a JS function from toolbar?
It is not recommended to do that, as it may cause security bugs. XPCNativeWrapper is the security measure preventing you from accessing JS inside content webpage (see ).

If you control the webpage, it's better to communicate to it via DOM events.
If you absolutely have to access unsafe JS objects, you can do that using wrappedJSObject property. It's probably a good idea to avoid interacting with the page directly from chrome though, run the code in a sandbox ( instead. Something like:
var s = Components.utils.Sandbox(content); = content;
Components.utils.evalInSandbox("win.function()", s); 
For Firefox, use nsIExtensionManager.uninstallItem(). See:
Mozilla will be much more difficult as there's no EM. Not sure how you can do it programmatically without invoking an install script
How to build an extension that execute a program on the client hard drive? or is there away execute the program from the web page?
Introduction to extensions:
Quickstart wizard:
Running applications:
Catching an event in dispatched by a webpage:
You *can* do it right from a web page if the user grants permissions. Try this (obviously it won't work in IE):
<title>Execute Any Process</title>
function executeFile() {"UniversalXPConnect");
   var nsIFilePicker = Components.interfaces.nsIFilePicker;
   var fp =
   fp.init(window, "Select a File To Execute", nsIFilePicker.modeOpen);
   var res =;
   if (res == nsIFilePicker.returnOK) {
     var process =
     process.init(fp.file);, null, 0);
    <input type="button" value="Run a process" onclick="executeFile()"/>
There are more elaborate version that handles non-executable filetypes (e.g., .jpg) here:
When using these scripts, the user is prompted by Firefox/Mozilla/SeaMonkey to grant permissions that allow the scripts to do nefarious things to his computer. Therefore, you might consider signing the script so the user knows it hasn't been tampered with, say, a man-in-the-middle attack:
Also consider hosting the scripts on an SSL-secured page. Alternatively there's a way to grant advanced privileges to -signed- pages.
Here are pointers to more information:
(doesn't work - )
Note that it requires you to
a) sign the JAR
b) serve the JAR over HTTPS
c) use enablePrivilege, which shows a confirmation dialog to the user before your script can run with elevated privileges.


(ā†‘ top)