Questions and answers from the newsgroups 2006 11 03

  • Revision slug: Extensions/Questions_and_answers_from_the_newsgroups_2006_11_03
  • Revision title: Questions and answers from the newsgroups 2006 11 03
  • Revision id: 183683
  • Created:
  • Creator: Mckwan
  • Is current revision? No
  • Comment

Revision Content

Return to mozilla-dev-extensions


FAQ

(↑ top)

Is there any way to view Firefox tab title?
Small tabs:
 1. Type: about:config to your address bar
 2. Type browser.tabs.tabMinWidth to filter
 3. Change value to something like 20 or smaller if you like
"Zoom": Put your mouse over the tab and a tooltip text should appear telling you the title for that tab.
Tab Preview : http://ted.mielczarek.org/code/mozilla/tabpreview/
How to get URL form address bar, redirect and update list from a central server?
1. Get URL in address bar with document.location
2. There are many ways to do this, but assuming you have your list of addresses in an array:
 if (myURLArray.some(function(e, i, a) {return document.location.indexOf(e)>-1;})) {
   // redirect
   document.location = "http://my.new.location.com";
 }
You might consider using a regular expression match instead of indexOf().
3. Use XmlHttpRequest() to retrieve the file, then XMLSerializer.serializeToStream() to write to disk.
How to screen grab use the command line?
There's no such thing as an "extension handle". Extension's functions can be defined in windows of certain type (e.g. browser.xul windows), in which case you need to get the window you need, e.g. using nsIWindowMediator.
Alternatively they can be defined in an XPCOM component, in which case you have to get your component via its contract id and either a) call a method on one of (IDL-defined) interfaces your component implements (you may need to create your own interface) or b) use the wrappedJSObject trick, which is, weirdly, not documented, but you can see it in the code on

http://kb.mozillazine.org/Dev_:_Extending_the_Chrome_Protocol

If Components.classes{{mediawiki.external('\"@your.name/yourcontractid\"')}} returns null, your component wasn't registered. I don't think we have troubleshooting guide for XPCOM components registration, but you should at least check that you put the component's JS file in your extension's components/folder, that it has a proper XPCOM registration code (copy it from http://forums.mozillazine.org/viewtopic.php?p=1694347&sid=518e2773c6c... if you don't understand it), and that there are no errors in the error console.
An extension is a bundle, which can provide various things, including chrome packages and components: http://developer.mozilla.org/en/docs/Bundles
After the extension is installed, mozilla will attempt to register its components on restart. It may fail to register them, in which case you'll indeed have the extension registered, but not the component.

====[http://groups.google.com/group/mozilla.dev.extensions/browse_frm/thread/77f96ad27ecb147a Would it be possible to intercept the socket event and set the socket to be SSL enabled so that FF can communicate with an SSL speaking proxy? ]====

It's a lot easier to tunnel the HTTP connection over SSL using stunnel or openssl... no coding necessary.
What you can do is set the network.http.default-socket-type preference and register a socket provider. However, you can only implement socket providers in C++... I suppose you could set that pref to "ssl", that might actually work (if you also set your HTTP proxy to something that accepts SSL).

====[http://groups.google.com/group/mozilla.dev.extensions/browse_frm/thread/77d0446c76310404 How to create an overlay of msgHeaderOverlay.xul which removes the current collaspedHeaderView element and adds a new one?]====

use the DOM API to remove elements. http://developer.mozilla.org/en/docs/DOM:element.removeChild
How to execute then command line example from mozilla site?
In order to cause auto-registration process, you'll also need to delete compreg.dat in your profile.
The call to nsICategory::addCategoryEntry in the example does it; but it's not related to the problem at hand.
Why extensions setup has all locales available for them?
This is a known issue and people are working on a fix.
Could someone update the Session Manager extension for Firefox 2?
FF 2.0 provides the following features of session manager out of the box:
- restore the session after a crash
- open closed tabs and windows (see History -> recently closed tabs)
- restore the session after restart
- restore the session after new start (see Preferences -> General -> Start -> ...)
The only feature which is not covered is the rstoring of multiple saved sessions.
You can use Bookmarks for that. Just create a folder with all the places You want to visit at once. Then You can pick Open All in Tabs from folders contaxt menu to open all of bookmarks in that folder.
How to create a web installable firefox extension?
place extension somewhere on the www
How to add two buttons to tabs-bar, or to buttons-bar to use as bookmarks button?
Install PrefBar from <http://prefbar.mozdev.org/>. Create a new PrefBar button named Bkmarks. In the onClick window, enter BrowserEditBookmarks(); Enable the button.
If you select the button, it will open Bookmarks Manager with its tree structure. That will allow you to select a bookmark to view the indicated Web page. That will also allow you to drag and drop the address of the current page into the bookmarks exactly where you want it.
If you merely want to see your bookmarks, do what I (and many others) do: Make your bookmarks.html file your home page. On the menu bar, select {{mediawiki.external('Edit > Preferences')}}. Under Category on the Preferences window, select Navigator. On the Navigator pane, under Home Page, select the Choose File button. On the Choose Home Page window, navigate to your profile and select bookmarks.html. Then, every time you select Home, you will get your bookmarks displayed as a Web page.
How to using the "wrappedJSObject" in an XPCOM component?
The "wrappedJSObject" property is just a way to get to the underlying JSObject of XPCOM components implemented in JavaScript. Presumably in most cases you're better off defining an interface to your component and then accessing it through that interface.
http://developer.mozilla.org/en/docs/How_to_Build_an_XPCOM_Component_...
The only thing to do differently from this example is to retrieve your component via getService rather than createInstance.
The uuidgen command-line tool, available (at least) on Mac OS X and in many Linux distributions (perhaps only with optional installation), will generate one of these. You can also get one by sending the message "uuid" to ssdbot on irc.mozilla.org. Or google "generate uuid" to find online generators.
Extension developer's best friend Ted Mielczarek is working on a component wizard. Dev version is here: http://mavra.perilith.com/~luser/jscomponentwiz/ The "Create as a service" checkbox doesn't work currently, but otherwise it's a very nice tool.
Is there is way to detect if a fellow extension is currently installed and enabled?
An easy way to do it is to test if an id is present from the extension.
For example:
 test = document.getElementById('myownextensionID');
 if (test) {
    // now you know it found the element so the extension must be present
 }

UAQ

(↑ top)

Revision Source

<p><a href="en/Newsgroup_summaries/mozilla-dev-extensions"> Return to mozilla-dev-extensions</a>
</p><p><br> 
</p>
<h3 name="FAQ"> FAQ </h3>
<p>(<a href="#top">↑ top</a>)
</p>
<div class="note">
<h5 name="Is_there_any_way_to_view_Firefox_tab_title.3F"><a class="external" href="http://groups.google.com/group/mozilla.dev.extensions/browse_frm/thread/ff31e4037eb5065d">Is there any way to view Firefox tab title?</a></h5>
<dl><dd> Small tabs:
</dd></dl>
<pre class="eval"> 1. Type: about:config to your address bar
 2. Type browser.tabs.tabMinWidth to filter
 3. Change value to something like 20 or smaller if you like
</pre>
<dl><dd> "Zoom": Put your mouse over the tab and a tooltip text should appear telling you the title for that tab. 
</dd></dl>
<dl><dd> Tab Preview : http://ted.mielczarek.org/code/mozilla/tabpreview/ 
</dd></dl>
</div>
<div class="note">
<h5 name="How_to_get_URL_form_address_bar.2C_redirect_and_update_list_from_a_central_server.3F"><a class="external" href="http://groups.google.com/group/mozilla.dev.extensions/browse_frm/thread/1f771289fe94a636">How to get URL form address bar, redirect and update list from a central server?</a></h5>
<dl><dd> 1. Get URL in address bar with document.location
</dd><dd> 2. There are many ways to do this, but assuming you have your list of addresses in an array:
</dd></dl>
<pre class="eval"> if (myURLArray.some(function(e, i, a) {return document.location.indexOf(e)&gt;-1;})) {
   // redirect
   document.location = "http://my.new.location.com";
 }
</pre>
<dl><dd> You might consider using a regular expression match instead of indexOf().
</dd><dd> 3. Use XmlHttpRequest()  to retrieve the file, then XMLSerializer.serializeToStream() to write to disk.
</dd></dl>
</div>
<div class="note">
<h5 name="How_to_screen_grab_use_the_command_line.3F"><a class="external" href="http://groups.google.com/group/mozilla.dev.extensions/browse_frm/thread/df139b7742eef728">How to screen grab use the command line?</a></h5>
<dl><dd> There's no such thing as an "extension handle". Extension's functions can be defined in windows of certain type (e.g. browser.xul windows), in which case you need to get the window you need, e.g. using nsIWindowMediator.
</dd></dl>
<dl><dd> Alternatively they can be defined in an XPCOM component, in which case you have to get your component via its contract id and either a) call a method on one of (IDL-defined) interfaces your component implements (you may need to create your own interface) or b) use the wrappedJSObject trick, which is, weirdly, not documented, but you can see it in the code on
</dd></dl>
<p>http://kb.mozillazine.org/Dev_:_Extending_the_Chrome_Protocol
</p>
<dl><dd> If Components.classes{{mediawiki.external('\"@your.name/yourcontractid\"')}} returns null, your component wasn't registered. I don't think we have troubleshooting guide for XPCOM components registration, but you should at least check that you put the component's JS file in your extension's components/folder, that it has a proper XPCOM registration code (copy it from http://forums.mozillazine.org/viewtopic.php?p=1694347&amp;sid=518e2773c6c... if you don't understand it), and that there are no errors in the error console. 
</dd></dl>
<dl><dd> An extension is a bundle, which can provide various things, including chrome packages and components: http://developer.mozilla.org/en/docs/Bundles
</dd></dl>
<dl><dd> After the extension is installed, mozilla will attempt to register its components on restart. It may fail to register them, in which case you'll indeed have the extension registered, but not the component. 
</dd></dl>
</div>
<div class="note">
<p>====[http://groups.google.com/group/mozilla.dev.extensions/browse_frm/thread/77f96ad27ecb147a Would it be possible to intercept the socket event and set the socket to
be SSL enabled so that FF can communicate with an SSL speaking proxy? ]====
</p>
<dl><dd> It's a lot easier to tunnel the HTTP connection over SSL using stunnel or openssl... no coding necessary.
</dd></dl>
<dl><dd> What you can do is set the network.http.default-socket-type preference and register a socket provider. However, you can only implement socket providers in C++... I suppose you could set that pref to "ssl", that might actually work (if you also set your HTTP proxy to something that accepts SSL). 
</dd></dl>
</div>
<div class="note">
<p>====[http://groups.google.com/group/mozilla.dev.extensions/browse_frm/thread/77d0446c76310404 How to create an overlay of msgHeaderOverlay.xul which removes the current 
collaspedHeaderView element and adds a new one?]====
</p>
<dl><dd> use the DOM API to remove elements. http://developer.mozilla.org/en/docs/DOM:element.removeChild 
</dd></dl>
</div>
<div class="note">
<h5 name="How_to_execute_then_command_line_example_from_mozilla_site.3F"><a class="external" href="http://groups.google.com/group/mozilla.dev.extensions/browse_frm/thread/485a300f319d2b0e">How to execute then command line example from mozilla site?</a></h5>
<dl><dd> In order to cause auto-registration process, you'll also need to delete compreg.dat in your profile. 
</dd></dl>
<dl><dd> The call to nsICategory::addCategoryEntry in the example does it; but it's not related to the problem at hand. 
</dd></dl>
</div>
<div class="note">
<h5 name="Why_extensions_setup_has_all_locales_available_for_them.3F"><a class="external" href="http://groups.google.com/group/mozilla.dev.extensions/browse_frm/thread/85b6166e6a5ceb47">Why extensions setup has all locales available for them?</a></h5>
<dl><dd> This is a known issue and people are working on a fix. 
</dd></dl>
</div>
<div class="note">
<h5 name="Could_someone_update_the_Session_Manager_extension_for_Firefox_2.3F"><a class="external" href="http://groups.google.com/group/mozilla.dev.extensions/browse_frm/thread/f0b79e4c542d4281">Could someone update the Session Manager extension for Firefox 2?</a></h5>
<dl><dd> FF 2.0 provides the following features of session manager out of the box:
</dd><dd> - restore the session after a crash
</dd><dd> - open closed tabs and windows (see History -&gt; recently closed tabs)
</dd><dd> - restore the session after restart
</dd><dd> - restore the session after new start (see Preferences -&gt; General -&gt; Start -&gt; ...)
</dd><dd> The only feature which is not covered is the rstoring of multiple saved sessions.
</dd></dl>
<dl><dd> You can use Bookmarks for that. Just create a folder with all the places You want to visit at once. Then You can pick Open All in Tabs from folders contaxt menu to open all of bookmarks in that folder. 
</dd></dl>
</div>
<div class="note">
<h5 name="How_to_create_a_web_installable_firefox_extension.3F"><a class="external" href="http://groups.google.com/group/mozilla.dev.extensions/browse_thread/thread/c956eecade2f2f60">How to create a web installable firefox extension?</a></h5>
<dl><dd> place extension somewhere on the www
</dd></dl>
</div>
<div class="note">
<h5 name="How_to_add_two_buttons_to_tabs-bar.2C_or_to_buttons-bar_to_use_as_bookmarks_button.3F"><a class="external" href="http://groups.google.com/group/mozilla.dev.extensions/browse_frm/thread/15ba7c6ad1629adb/4ff350b3e8733c98?tvc=1#4ff350b3e8733c98">How to add two buttons to tabs-bar, or to buttons-bar to use as bookmarks button?</a></h5>
<dl><dd> Install PrefBar from &lt;http://prefbar.mozdev.org/&gt;.  Create a new PrefBar button named Bkmarks.  In the onClick window, enter         BrowserEditBookmarks(); Enable the button. 
</dd></dl>
<dl><dd> If you select the button, it will open Bookmarks Manager with its tree structure.  That will allow you to select a bookmark to view the indicated Web page.  That will also allow you to drag and drop the address of the current page into the bookmarks exactly where you want it.
</dd></dl>
<dl><dd> If you merely want to see your bookmarks, do what I (and many others) do:  Make your bookmarks.html file your home page.  On the menu bar, select {{mediawiki.external('Edit &gt; Preferences')}}.  Under Category on the Preferences window, select Navigator.  On the Navigator pane, under Home Page, select the Choose File button.  On the Choose Home Page window, navigate to your profile and select bookmarks.html.  Then, every time you select Home, you will get your bookmarks displayed as a Web page. 
</dd></dl>
</div>
<div class="note">
<h5 name="How_to_using_the_.22wrappedJSObject.22_in_an_XPCOM_component.3F"><a class="external" href="http://groups.google.com/group/mozilla.dev.extensions/browse_frm/thread/df6e69617cd747e2">How to using the "wrappedJSObject" in an XPCOM component?</a></h5>
<dl><dd> The "wrappedJSObject" property is just a way to get to the underlying JSObject of XPCOM components implemented in JavaScript.  Presumably in most cases you're better off defining an interface to your component and then accessing it through that interface. 
</dd></dl>
<dl><dd> http://developer.mozilla.org/en/docs/How_to_Build_an_XPCOM_Component_...
</dd><dd> The only thing to do differently from this example is to retrieve your component via getService rather than createInstance. 
</dd></dl>
<dl><dd>The uuidgen command-line tool, available (at least) on Mac OS X and in many Linux distributions (perhaps only with optional installation), will generate one of these.  You can also get one by sending the message "uuid" to ssdbot on irc.mozilla.org.  Or google "generate uuid" to find online generators. 
</dd></dl>
<dl><dd> Extension developer's best friend Ted Mielczarek is working on a component wizard. Dev version is here: http://mavra.perilith.com/~luser/jscomponentwiz/ The "Create as a service" checkbox doesn't work currently, but otherwise it's a very nice tool. 
</dd></dl>
</div>
<div class="note">
<h5 name="Is_there_is_way_to_detect_if_a_fellow_extension_is_currently_installed_and_enabled.3F"><a class="external" href="http://groups.google.com/group/mozilla.dev.extensions/browse_frm/thread/d19bbfbb360ffec0/c44922ad5df12826#c44922ad5df12826">Is there is way to detect if a fellow extension is currently installed and enabled? </a></h5>
<dl><dd> An easy way to do it is to test if an id is present from the extension.
</dd><dd> For example:
</dd></dl>
<pre class="eval"> test = document.getElementById('myownextensionID');
 if (test) {
    // now you know it found the element so the extension must be present
 }
</pre>
</div>
<h3 name="UAQ"> UAQ </h3>
<p>(<a href="#top">↑ top</a>)
</p>
<div class="note">
<h5 name="Is_there_any_way_to_forcing_nsWebBrowserPersist_service_to_finish_its_job.3F"><a class="external" href="http://groups.google.com/group/mozilla.dev.extensions/browse_frm/thread/15dfde8a554db572/8bf65f32526a7454#8bf65f32526a7454">Is there any way to forcing nsWebBrowserPersist service to finish its job?</a></h5>
</div>
<div class="note">
<h5 name="How_to_post_data_using_nsIWebNavigation.loadURI.3F"><a class="external" href="http://groups.google.com/group/mozilla.dev.extensions/browse_frm/thread/fc2e0450de6f8966">How to post data using nsIWebNavigation.loadURI?</a></h5>
</div>
<div class="note">
<h5 name="How_to_expose_a_JS_constructor_with_.28non-const.29_properties_to_content.3F"><a class="external" href="http://groups.google.com/group/mozilla.dev.extensions/browse_frm/thread/1ad4fd0ad2b9fcbd">How to expose a JS constructor with (non-const) properties to content?</a></h5>
</div>
<div class="note">
<h5 name="How_to_write_a_.aff_file.3F"><a class="external" href="http://groups.google.com/group/mozilla.dev.extensions/browse_frm/thread/9e170ab82ac856a2">How to write a .aff file?</a></h5>
</div>
<div class="note">
<h5 name="Could_anyone_tell_me_how_to_add_a_button_that_opens_up_the_default_mail_program.3F"><a class="external" href="http://groups.google.com/group/mozilla.dev.extensions/browse_frm/thread/34be73182504f576">Could anyone tell me how to add a button that opens up the default mail program?</a></h5>
</div>
<div class="note">
<h5 name="How_to_write_T-bird_popup_mail_notification_extension.3F"><a class="external" href="http://groups.google.com/group/mozilla.dev.extensions/browse_frm/thread/c31a8c8431e5851a">How to write T-bird popup mail notification extension?</a></h5>
</div>
<div class="note">
<h5 name="How_to_make_the_browser_use_the_newly_created_streamconverter_instead_of_the_default_one.3F"><a class="external" href="http://groups.google.com/group/mozilla.dev.extensions/browse_frm/thread/271d96f2c11c8bbc">How to make the browser use the newly created streamconverter instead of the default one? </a></h5>
</div>
Revert to this revision