Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Like lwburk, I don't think its available through Mozilla's API's, but I have an idea which works, but it seems like a complex hack. The basic steps are:</p> <ol> <li>Set up a custom resource url to point to your extension's base directory</li> <li>Read the file and parse it into XML</li> <li>Pull the id out using <a href="https://developer.mozilla.org/en/xpath" rel="nofollow">XPath</a></li> </ol> <p>Add the following line to your chrome.manifest file</p> <pre><code>resource packagename-base-dir chrome/../ </code></pre> <p>Then we can grab and parse the file with the following code:</p> <pre><code>function myId(){ var req = new XMLHttpRequest(); // synchronous request req.open('GET', "resource://packagename-base-dir/install.rdf", false); req.send(null); if( req.status !== 0){ throw("file not found"); } var data = req.responseText; // this is so that we can query xpath with namespaces var nsResolver = function(prefix){ var ns = { "rdf" : "http://www.w3.org/1999/02/22-rdf-syntax-ns#", "em" : "http://www.mozilla.org/2004/em-rdf#" }; return ns[prefix] || null; }; var parser = CCIN("@mozilla.org/xmlextras/domparser;1", Ci.nsIDOMParser); var doc = parser.parseFromString(data, "text/xml"); // you might have to change this xpath expression a bit to fit your setup var myExtId = doc.evaluate("//em:targetApplication//em:id", doc, nsResolver, Ci.nsIDOMXPathResult.FIRST_ORDERED_NODE_TYPE, null); return myExtId.singleNodeValue.textContent; } </code></pre> <p>I chose to use a XMLHttpRequest(as opposed to simply reading from a file) to retrieve the contents since in Firefox 4, extensions aren't necessarily unzipped. However, XMLHttpRequest will still work if the extension remains packed (haven't tested this, but have read about it).</p> <p>Please note that resource URL's are shared by all installed extensions, so if <code>packagename-base-dir</code> isn't unique, you'll run into problems. You might be able to leverage <a href="https://developer.mozilla.org/en/JavaScript_code_modules/Using#Programmatically_adding_aliases" rel="nofollow">Programmatically adding aliases</a> to solve this problem.</p> <p><em>This question prompted me to join StackOverflow tonight, and I'm looking forward participating more... I'll be seeing you guys around!</em></p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload