Firefox: How to install and use addon that is not from AMO

In former version, users can install Firefox addon easily by drag and drop the addon file (.xpi file)  into Firefox to install and use it.

But now, user can not do this by default. User can only install addon from AMO (https://addon.mozilla.org). If you download an addon from other website or like me develop addon self. when you drag and drop the file into Firefox. it will be disabled and can not be enable. It says : ADDON NAME could not be verified for use in Firefox and has been disabled.  like this(I’m using Nightly Firefox):

Unnamed QQ Screenshot20151104000045

well, it’s easy to pass this by these steps.

1: Navigate to about:config in Firefox (input about:config into Firefox’s address bar and hit Enter)

2: You might see a warning screen warning the action is not safe. Just hit the blue button  I’ll be careful, I promise .

3:You will see a long list. Input the keywords xpinstall  in the search bar.

4: Find the xpinstall.signatures.required, it’s value should be true now. click this line, change the value to false.

xpinstall

5: You are done, you will see that your addon enabled and working:)

 

Firefox Addon: How to use gmail.js in Firefox Addon SDK

Well, gmail.js is a very nice script that if you want to work with Gmail (developing browser extensions for Gmail).

The author says that gmail.js is designed for Chrome extension development. There is also many examples about how to use it in Chrome extension. But, how to use it in Firefox addon development?

If you inject it directly in the page, you will got an error: GLOBAL is not defined.

it is because the gmail.js uses 2 variables in the Gmail page, GLOBAL  and also VIEW_DATA. If you inject it directly by pageMode, it can not access any page script.

So you need to modify the gmail.js, in line 6 and 7 (if line number is different, just search it ). By using unsafeWindow , you can access the Gmail page variable:
change

api.tracker.globals =GLOBALS;

to
api.tracker.globals = unsafeWindow.GLOBALS;

change

api.tracker.view_data = typeof VIEW_DATA !== "undefined" ? VIEW_DATA : [];

to

api.tracker.view_data = typeof unsafeWindow.VIEW_DATA !== "undefined" ? unsafeWindow.VIEW_DATA : [];

Then you can use the gmail.js without error.

Actually in Chrome extension, you can not inject gmail.js with content script decoration in manifest.json directly, because in that way  you can not access GLOBAL too.

You need to use another content script to inject it  with add <script> block in the page, here  is the code snap

window.onload = function () {

    //inject jQuery
    var jq = document.createElement('script');
    jq.src = chrome.extension.getURL("lib/jquery-2.1.1.min.js");
    document.body.appendChild(jq)

    //inject gmail.js
    var sm = document.createElement('script');
    sm.src = chrome.extension.getURL("lib/gmail.js");
    document.body.appendChild(sm);
    //inject the script that actual do your things 
    var ct = document.createElement('script');
    ct.src = chrome.extension.getURL("content.js");
    document.body.appendChild(ct);
}

Then declare this file as content script in the manifest.json. and also declare all 3 scripts in web_accessible_resources.