问题
So I am following the documentation/tutorial here:
https://developer.mozilla.org/en-US/Add-ons/SDK/Tutorials/Getting_started
The add on shows up correctly when I use cfx run but when I export to xpi and install on my own installation of firefox no icon shows up in the top right corner. I have Firefox version 31 installed and have an unrelated add on installed and its icon shows up where it should in the top right corner but my add on does not. My add on shows up as enable / installed under Extensions in the Add-ons Manager.
I installed my add on through the process they described:
To test that this worked, try installing the XPI file in your own Firefox installation. You can do this by pressing the Ctrl+O key combination (Cmd+O on Mac) from within Firefox, or selecting the "Open" item from Firefox's "File" menu. This will bring up a file selection dialog: navigate to the "my-addon.xpi" file, open it and follow the prompts to install the add-on.
Here is the code for my main.js (as per previous link, which works as expected with cfx run) :
var buttons = require('sdk/ui/button/action');
var tabs = require("sdk/tabs");
var button = buttons.ActionButton({
id: "mozilla-link",
label: "Visit Mozilla",
icon: {
"16": "./icon-16.png",
"32": "./icon-32.png",
"64": "./icon-64.png"
},
onClick: handleClick
});
function handleClick(state) {
tabs.open("http://www.mozilla.org/");
}
I don't get any browser console messages upon enabling the add-on but when I disable the add-on I get the following:
Duplicate resource declaration for 'specialpowers' ignored. chrome.manifest:32
Duplicate resource declaration for 'gre-resources' ignored. chrome.manifest:34
Duplicate resource declaration for 'services-sync' ignored. components.manifest:168
Duplicate resource declaration for 'services-common' ignored. components.manifest:170
Duplicate resource declaration for 'services-crypto' ignored. components.manifest:171
Could not read chrome manifest 'file:///C:/Program%20Files%20(x86)/Mozilla%20Firefox/chrome.manifest'.
Duplicate resource declaration for 'pdf.js' ignored. pdfjs.manifest:1
Could not read chrome manifest 'file:///C:/Program%20Files%20(x86)/Mozilla%20Firefox/browser/extensions/%7B972ce4c6-7e08-4474-a285-3208198ce6fd%7D/chrome.manifest'.
回答1:
I had the same problem and solved it by changing the package.json file to allow the addon working in the private mode, see here: https://developer.mozilla.org/en-US/Add-ons/SDK/High-Level_APIs/private-browsing#Opting_into_private_browsing . I guess the reason it works when you type cfx run is that it uses a different profile that has not enabled private browsing by default. Hope this helps :)
回答2:
It's hard to tell what might have gone wrong based on what you'd said. Can you add to your question with the code that isn't working. Quite often this sort of thing happens when you have an unnoticed syntax error in your code.
You can also see of the add-on is producing errors on install - try this method:
- open the browser console ( ctrl+shift+j on win/linux, cmd+shift+j on OS X ) or:
- open the addon manager ( ctrl+shift+a on win/linux, cmd+shift+a on OS X ), locate your extension in the list of extensions:
Switch back the broser console window and click on 'clear' to clear all existing messages
switch back to the add-on manager and disable, then enable your add-on
finally, switch back to the browser console again and see if any error messages are showing.
回答3:
One of your add-ons might conflict with your new add-on in some way (for example, another add-on might already have an element with ID "mozilla-link"). Try disabling all your other add-ons and see if your new add-on starts working.
来源:https://stackoverflow.com/questions/25319522/firefox-sdk-sample-add-on-exported-xpi-action-button-doesnt-show-up