Search code examples
javascriptfirefoxfirefox-addonxpi

Re-packaging and/or modifying an existing Firefox extension XPI


I am an advanced user and have some programmer skills but I have installed some firefox add-on and I'd like to add some extra code line to original code. But I've only got .xpi file.

I know it can be opened by any zip utility. But it doesn't work when I change something in there. It stores .js file in CONTENT folder. There is an output-to-file function and I want to format a string a little bit that is being saved into a file.

You can to not mention the beginning of the question but there is the main goal and question: How to recompile or apply any changes to .js files in installed .xpi extensions? Any ways to upgrade them.

Add-ons:

url-logger

http-request-logger


Solution

  • Essentially you just zip up stuff again (non-SDK add-ons). And those add-ons you linked are non-SDK add-ons.

    However there are some pitfalls:

    • The extension might have been digitally signed, as indicated by the presence of a META-INF folder. Modifying stuff will of course invalidate the signature. Just remove the folder to make the (modified) extension unsigned again.
    • Quite often people actually zip up the outer folder. I.e. the resulting zip (.xpi) then contains /some-addon-folder/install.rdf instead of just /install.rdf. Make sure to not zip the outer folder, just the files and subfolders within.
    • Some zip tools produce zip files that are essentially broken; broken enough to be rejected by Firefox but not broken enough for other zip utilities to break. Make sure the zip if valid and if in doubt switch the zip utility you use.
    • Also remember to actually ZIP stuff as opposed to 7zip, rar, tar.gz, or whatever. ;)

    This is correctly zipped:

    $ unzip -l http_request_logger-0.1-fx.xpi 
    Archive:  http_request_logger-0.1-fx.xpi
      Length     Date   Time    Name
     --------    ----   ----    ----
          240  07-29-11 11:45   chrome.manifest
            0  07-29-11 11:42   components/
         1558  07-29-11 11:47   components/httpRequestLogger.js
         1021  07-30-11 12:39   install.rdf
     --------                   -------
         2819                   4 files
    

    This is not correctly zipped (produced by using the OSX compress menu item):

    $ unzip -l http_request_logger-0.1-fx.zip 
    Archive:  http_request_logger-0.1-fx.zip
      Length     Date   Time    Name
     --------    ----   ----    ----
            0  05-16-14 01:54   http_request_logger-0.1-fx/
          240  07-29-11 11:45   http_request_logger-0.1-fx/chrome.manifest
            0  05-16-14 01:54   __MACOSX/
            0  05-16-14 01:54   __MACOSX/http_request_logger-0.1-fx/
          187  07-29-11 11:45   __MACOSX/http_request_logger-0.1-fx/._chrome.manifest
            0  07-29-11 11:42   http_request_logger-0.1-fx/components/
         1558  07-29-11 11:47   http_request_logger-0.1-fx/components/httpRequestLogger.js
            0  05-16-14 01:54   __MACOSX/http_request_logger-0.1-fx/components/
          187  07-29-11 11:47   __MACOSX/http_request_logger-0.1-fx/components/._httpRequestLogger.js
         1021  07-30-11 12:39   http_request_logger-0.1-fx/install.rdf
          187  07-30-11 12:39   __MACOSX/http_request_logger-0.1-fx/._install.rdf
          187  05-16-14 01:54   __MACOSX/._http_request_logger-0.1-fx
     --------                   -------
         3567                   12 files
    

    (Aside from the __MACOSX crap, it is http_request_logger-0.1-fx/install.rdf now)

    I recommend you also read Setting up an extension development enviroment, in particular the bits about the proxy file. ;)

    When it comes to SDK add-ons (as indicated by the presence of a harness-options.json file), re-zipping may or not work. It might be better to just reproduce a package.json and directory structure based on the .xpi contents and use the SDK cfx tool to build a new XPI.