Questions and answers from the newsgroups 2006 11 24

  • Revision slug: Extensions/Questions_and_answers_from_the_newsgroups_2006_11_24
  • Revision title: Questions and answers from the newsgroups 2006 11 24
  • Revision id: 186615
  • Created:
  • Creator: Mckwan
  • Is current revision? No
  • Comment /* FAQ */

Revision Content

Return to mozilla-dev-extensions


FAQ

(↑ top)

How to make Sidebar work like a normal Page, with Ctrl-Click for new Tabs and Right-Click for Context Menu?
Put the file with the links in an HTML file, and included it like this.
<iframe id="gj53run-sidebar-iframe" flex="1"
src="chrome://gj53run/content/CookBook/MySidebar.htm"/>
example xul file
<?xml version="1.0"?>
<?xml-stylesheet href="chrome://global/skin" type="text/css"?>
<?xml-stylesheet href="chrome://gj53run/skin/gj53run.css"
type="text/css"?>
<!DOCTYPE window SYSTEM "chrome://gj53run/locale/gj53run.dtd">
<window
xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul"
                               xmlns:html="http://www.w3.org/1999/xhtml"
                               id="gj53run-ShowMenu-sidebar"
       onload="gj53runSidebarMenuOnload()"
       onunload="gj53runSidebarMenuOnUnload()">
<script type="application/x-javascript"
src="chrome://gj53run/content/utilsxul.js"/>
<script type="application/x-javascript"
src="chrome://gj53run/content/gj53runMenuXUL.js"/>
<iframe id="gj53run-sidebar-iframe" flex="1"
src="chrome://gj53run/content/CookBook/MySidebar.htm"/>
</window>
Then something like this in your overlay will work
<broadcaster  id="gj53run-xxh-sidebar"
                     autoCheck="false"
                     label="&gj53run.menuitem.SFT2.label;"
                     type="checkbox" group="sidebar"
                     sidebarurl="chrome://gj53run/content/xxxx.xul"
oncommand="toggleSidebar('gj53run-xxxxx-sidebar');"/>
If you follow the links from www.cookdotcom.com you can download my alpha extension.
There is a working example their, it the main menu
How to create a log when a user visits a site in Firefox?
Add an event listener to the window object to call your function when a browser window as loaded.
       window.addEvenListener("load", MyExtension.init, false);
In that function, get the current URL. If it's what you're looking for, create write to a log file.
For more info, check:
       http://developer.mozilla.org/en/docs/DOM:window (window.location)
       http://developer.mozilla.org/en/docs/Code_snippets:File_I/O 
Is it possible to Detect the presence of specific extension from JavaScript?
You could use the DOM events to talk to the installed extension, see http://forums.mozillazine.org/viewtopic.php?p=1005555#1005555 for description and http://circum.com/startalocalprogram.html for an example.
It is also possible to make an object accessible to webpage JS via a global property - see nsSidebar.js
You could create a dummy plugin (and install it together with itunes) which would then be visible via navigator.plugins <http://developer.mozilla.org/en/docs/navigator.plugins>
Not to mention this url from some obscure hardware company. <http://developer.apple.com/internet/webcontent/examples/detectplugins...>
You could also append a string to the useragent. See http://www.mozilla.org/build/revised-user-agent-strings.html#implemen... for details.
How to create an extension to get selected text from browser?
See window.getSelection here: http://developer.mozilla.org/en/docs/DOM:window.getSelection
var focusedWindow = document.commandDispatcher.focusedWindow;
var winWrapper = new XPCNativeWrapper(focusedWindow, "window", "getSelection()"); 
var string = winWrapper.getSelection().toString(); 
Is there a BrowserInitialized event?
Use the strategy of attaching an init script to the window.onload event:
<script type="application/x-javascript">
  <![CDATA[
     window.addEventListener('load', MyFunction.init, false);  
  ]]>
</script> 
For tabs, attach a listener to the tab container:
//attach listener to new tab in seamonkey brower
   container = gBrowser.mPanelContainer;
   container.addEventListener("DOMNodeInserted", MyFunction.processPage, true); 
Is there some service or method to getting the current profile or extension folder path?
Use the __LOCATION__ trick documented here: http://developer.mozilla.org/en/docs/Creating_Custom_Firefox_Extensio...
How to control flashmovies with a firefox extension?
Make certain to use Mook's javascript function to test if the movie is 100% loaded before calling stop. Possibly you could use the setTimeout and setInterval functions from an extension to check at a certain interval and probe the Flash movies for their loading status. Once the loading is 100% then call stop. These routines could be started from a window.onload script in your extension.
// Checks if movie is completely loaded.
// Returns true if yes, false if no.
function movieIsLoaded (theMovie) {
 // First make sure the movie's defined.
 if (typeof(theMovie) != "undefined") {
   // If it is, check how much of it is loaded.
   return theMovie.PercentLoaded() == 100;
 } else {
   // If the movie isn't defined, it's not loaded.
   return false;
 } 
If you are accessing webcontent from chrome, you may need to use the JSWrappedObject property to access unsafe methods.

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="How_to_make_Sidebar_work_like_a_normal_Page.2C_with_Ctrl-Click_for_new_Tabs_and_Right-Click_for_Context_Menu.3F"><a class="external" href="http://groups.google.com/group/mozilla.dev.extensions/browse_thread/thread/1040c979ba76f06e/80cf13af37033957#80cf13af37033957">How to make Sidebar work like a normal Page, with Ctrl-Click for new Tabs and Right-Click for Context Menu?</a></h5>
<dl><dd> Put the file with the links in an HTML file, and included it like this.
</dd></dl>
<pre class="eval">&lt;iframe id="gj53run-sidebar-iframe" flex="1"
src="chrome://gj53run/content/CookBook/MySidebar.htm"/&gt;
</pre>
<dl><dd> example xul file
</dd></dl>
<pre class="eval">&lt;?xml version="1.0"?&gt;
&lt;?xml-stylesheet href="chrome://global/skin" type="text/css"?&gt;
&lt;?xml-stylesheet href="chrome://gj53run/skin/gj53run.css"
type="text/css"?&gt;
&lt;!DOCTYPE window SYSTEM "chrome://gj53run/locale/gj53run.dtd"&gt;
&lt;window
xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul"
                               xmlns:html="http://www.w3.org/1999/xhtml"
                               id="gj53run-ShowMenu-sidebar"
       onload="gj53runSidebarMenuOnload()"
       onunload="gj53runSidebarMenuOnUnload()"&gt;
&lt;script type="application/x-javascript"
src="chrome://gj53run/content/utilsxul.js"/&gt;
&lt;script type="application/x-javascript"
src="chrome://gj53run/content/gj53runMenuXUL.js"/&gt;
&lt;iframe id="gj53run-sidebar-iframe" flex="1"
src="chrome://gj53run/content/CookBook/MySidebar.htm"/&gt;
&lt;/window&gt;
</pre>
<dl><dd> Then something like this in your overlay will work
</dd></dl>
<pre class="eval">&lt;broadcaster  id="gj53run-xxh-sidebar"
                     autoCheck="false"
                     label="&amp;gj53run.menuitem.SFT2.label;"
                     type="checkbox" group="sidebar"
                     sidebarurl="chrome://gj53run/content/xxxx.xul"
oncommand="toggleSidebar('gj53run-xxxxx-sidebar');"/&gt;
</pre>
<dl><dd> If you follow the links from www.cookdotcom.com you can download my alpha extension.
</dd><dd> There is a working example their, it the main menu 
</dd></dl>
</div>
<div class="note">
<h5 name="How_to_create_a_log_when_a_user_visits_a_site_in_Firefox.3F"><a class="external" href="http://groups.google.com/group/mozilla.dev.extensions/browse_thread/thread/89d4249e7fda2f71">How to create a log when a user visits a site in Firefox?</a></h5>
<dl><dd> Add an event listener to the window object to call your function when a browser window as loaded.
</dd></dl>
<pre class="eval">       window.addEvenListener("load", MyExtension.init, false);
</pre>
<dl><dd> In that function, get the current URL. If it's what you're looking for, create write to a log file.
</dd><dd> For more info, check:
</dd></dl>
<pre class="eval">       http://developer.mozilla.org/en/docs/DOM:window (window.location)
       http://developer.mozilla.org/en/docs/Code_snippets:File_I/O 
</pre>
</div>
<div class="note">
<h5 name="Is_it_possible_to_Detect_the_presence_of_specific_extension_from_JavaScript.3F"><a class="external" href="http://groups.google.com/group/mozilla.dev.extensions/browse_thread/thread/60f7595f172d7197">Is it possible to Detect the presence of specific extension from JavaScript?</a></h5>
<dl><dd> You could use the DOM events to talk to the installed extension, see http://forums.mozillazine.org/viewtopic.php?p=1005555#1005555 for description and http://circum.com/startalocalprogram.html for an example.
</dd><dd> It is also possible to make an object accessible to webpage JS via a global property - see nsSidebar.js
</dd></dl>
<dl><dd>You could create a dummy plugin (and install it together with itunes) which would then be visible via navigator.plugins &lt;http://developer.mozilla.org/en/docs/navigator.plugins&gt;
</dd><dd> Not to mention this url from some obscure hardware company. &lt;http://developer.apple.com/internet/webcontent/examples/detectplugins...&gt; 
</dd></dl>
<dl><dd> You could also append a string to the useragent.  See http://www.mozilla.org/build/revised-user-agent-strings.html#implemen... for details. 
</dd></dl>
</div>
<div class="note">
<h5 name="How_to_create_an_extension_to_get_selected_text_from_browser.3F"><a class="external" href="http://groups.google.com/group/mozilla.dev.extensions/browse_thread/thread/32cfb2b108a2f692">How to create an extension to get selected text from browser?</a></h5>
<dl><dd> See window.getSelection here: http://developer.mozilla.org/en/docs/DOM:window.getSelection 
</dd></dl>
<pre class="eval">var focusedWindow = document.commandDispatcher.focusedWindow;
var winWrapper = new XPCNativeWrapper(focusedWindow, "window", "getSelection()"); 
var string = winWrapper.getSelection().toString(); 
</pre>
</div>
<div class="note">
<h5 name="Is_there_a_BrowserInitialized_event.3F"><a class="external" href="http://groups.google.com/group/mozilla.dev.extensions/browse_thread/thread/d44475080255c62b">Is there a BrowserInitialized event?</a></h5>
<dl><dd> Use the strategy of attaching an init script to the window.onload event:
</dd></dl>
<pre class="eval">&lt;script type="application/x-javascript"&gt;
  &lt;![CDATA[
     window.addEventListener('load', MyFunction.init, false);  
  ]]&gt;
&lt;/script&gt; 
</pre>
<dl><dd> For tabs, attach a listener to the tab container:
</dd></dl>
<pre class="eval">//attach listener to new tab in seamonkey brower
   container = gBrowser.mPanelContainer;
   container.addEventListener("DOMNodeInserted", MyFunction.processPage, true); 
</pre>
</div>
<div class="note">
<h5 name="Is_there_some_service_or_method_to_getting_the_current_profile_or_extension_folder_path.3F"><a class="external" href="http://groups.google.com/group/mozilla.dev.extensions/browse_thread/thread/7df3952aad134252">Is there some service or method to getting the current profile or extension folder path?</a></h5>
<dl><dd>  Use the __LOCATION__ trick documented here: http://developer.mozilla.org/en/docs/Creating_Custom_Firefox_Extensio... 
</dd></dl>
</div>
<div class="note">
<h5 name="How_to_control_flashmovies_with_a_firefox_extension.3F"><a class="external" href="http://groups.google.com/group/mozilla.dev.extensions/browse_thread/thread/3dceec0b17ac599a">How to control flashmovies with a firefox extension?</a></h5>
<dl><dd> Make certain to use Mook's javascript function to test if the movie is 100% loaded before calling stop. Possibly you could use the setTimeout and setInterval functions from an extension to check at a certain interval and probe the Flash movies for their loading status. Once the loading is 100% then call stop. These routines could be started from a window.onload script in your extension.
</dd></dl>
<pre class="eval">// Checks if movie is completely loaded.
// Returns true if yes, false if no.
function movieIsLoaded (theMovie) {
 // First make sure the movie's defined.
 if (typeof(theMovie) != "undefined") {
   // If it is, check how much of it is loaded.
   return theMovie.PercentLoaded() == 100;
 } else {
   // If the movie isn't defined, it's not loaded.
   return false;
 } 
</pre>
<dl><dd> If you are accessing webcontent from chrome, you may need to use the JSWrappedObject property to access unsafe methods. 
</dd></dl>
</div>
<h3 name="UAQ"> UAQ </h3>
<p>(<a href="#top">↑ top</a>)
</p>
<div class="note">
<h5 name="Any_info_on_.28Combine_and_Decode.29_with_Thunderbird_in_newsgroups.3F"><a class="external" href="http://groups.google.com/group/mozilla.dev.extensions/browse_thread/thread/5616ea4b9d431a18">Any info on (Combine and Decode) with Thunderbird in newsgroups?</a></h5>
</div>
<div class="note">
<h5 name="How_to_detect_server_socket_listeners.3F"><a class="external" href="http://groups.google.com/group/mozilla.dev.extensions/browse_thread/thread/572e0439f75e59c7">How to detect server socket listeners?</a></h5>
</div>
<div class="note">
<h5 name="What_type_of_case_testing_should_be_done_to_the_extension.3F"><a class="external" href="http://groups.google.com/group/mozilla.dev.extensions/browse_thread/thread/72b88b5fb108eb8e">What type of case testing should be done to the extension?</a></h5>
</div>
<div class="note">
<h5 name="Is_there_issues_with_Restart_button.3F"><a class="external" href="http://groups.google.com/group/mozilla.dev.extensions/browse_thread/thread/d7ecb87a31ee65ee">Is there issues with Restart button?</a></h5>
</div>
<div class="note">
<h5 name="How_to_change_cursor_position.3F"><a class="external" href="http://groups.google.com/group/mozilla.dev.extensions/browse_thread/thread/006e1400bcfac65e">How to change cursor position?</a></h5>
</div>
<div class="note">
<h5 name="How_can_one_tell_if_the_Async_stream_listeners_callback_trigger_is_.22ready.22_or_closed.22.3F_Can_there_be_more_than_one_registered_listener_on_a_single_Async_stream.3F"><a class="external" href="http://groups.google.com/group/mozilla.dev.extensions/browse_thread/thread/0f55b2d9376cc678">How can one tell if the Async stream listeners callback trigger is "ready" or closed"? Can there be more than one registered listener on a single Async stream?</a></h5>
</div>
<div class="note">
<h5 name="How_to_open_a_second_tool_bar_when_a_user.2C_click_in_a_button_in_a_first_tool_bar_.3F"><a class="external" href="http://groups.google.com/group/mozilla.dev.extensions/browse_thread/thread/5f87c2e8a2ea2b1c">How to open a second tool bar when a user, click in a button in a first tool bar ?</a></h5>
</div>
Revert to this revision