Jetpack/FAQ: Difference between revisions

no edit summary
mNo edit summary
No edit summary
Line 21: Line 21:
The tools are designed to produce add-ons that will be forwards-compatible with future versions of Firefox, so you won't need to update your add-on every time a new version of Firefox is released. Add-on SDK and Add-on Builder-based add-ons benefit from a security model that limits the harm that can be caused by a vulnerability in add-on code.
The tools are designed to produce add-ons that will be forwards-compatible with future versions of Firefox, so you won't need to update your add-on every time a new version of Firefox is released. Add-on SDK and Add-on Builder-based add-ons benefit from a security model that limits the harm that can be caused by a vulnerability in add-on code.
                                          
                                          
Finally, the Add-on SDK and Add-on Builder implement the [http://www.commonjs.org/ CommonJS] Packages and Modules specifications to enable a rich ecosystem of third-party APIs that developers can use to build their add-ons in addition to the APIs built into the Add-on SDK and Add-on Builder itself. We maintain a page listing some of the [https://wiki.mozilla.org/Labs/Jetpack/Modules extra third-party APIs] you can use in your add-on.
Finally, the Add-on SDK and Add-on Builder implement the [http://www.commonjs.org/ CommonJS] Packages and Modules specifications to enable a rich ecosystem of third-party APIs that developers can use to build their add-ons in addition to the APIs built into the Add-on SDK itself. We maintain a page listing some of the [https://wiki.mozilla.org/Labs/Jetpack/Modules extra third-party APIs] you can use in your add-on.


''' What are the benefits to users add-ons created with the Add-on SDK and Add-on Builder? '''
''' What are the benefits to users of add-ons created with the Add-on SDK and Add-on Builder? '''


Add-ons created with the Add-on Builder or the Add-on SDK are restartless by default, meaning users can install and remove add-ons built with these tools instantly, without a browser restart. This makes it easier to try add-ons and personalize their browsing experience.   
Add-ons created with the Add-on Builder or the Add-on SDK are restartless by default, meaning users can install and remove add-ons built with these tools instantly, without interrupting their browser experience through a browser restart. This makes it easier to try add-ons and personalize their browsing experience.   


Developers and users alike also will not have to worry about add-on compatibility with new versions of Firefox.  
Developers and users alike also will not have to worry about add-on compatibility with new versions of Firefox.  
Line 39: Line 39:
* loading your own XPCOM components, both binary and JavaScript.
* loading your own XPCOM components, both binary and JavaScript.


You have to do some things differently: in particular, you can't use XUL overlays in SDK-based add-ons because they are not compatible with restartless add-ons. Instead, you have to use DOM manipulation.
You have to do some things differently: in particular, you can't use XUL overlays in Builder / SDK-based add-ons because they are not compatible with restartless add-ons. Instead, you have to use DOM manipulation.


Add-on Builder is aimed primarily at Web developers who wish to write add-ons but are unfamiliar with the traditional XUL-based approach. So it supports a set of easy-to-use high level JavaScript APIs which address the most common use cases encountered by add-on developers. Using only the high level APIs, you can't do everything a XUL-based add-on can do.
Add-on Builder and the Add-on SDK are aimed primarily at Web developers who wish to write add-ons but are unfamiliar with the traditional XUL-based approach. So it supports a set of easy-to-use high level JavaScript APIs which address the most common use cases encountered by add-on developers. Using only the high level APIs, you can't do everything a XUL-based add-on can do.


After shipping 1.0 one of our top priorities is to help developers migrate from XUL-based add-ons to Builder/SDK based add-ons, so implementing advanced add-ons will become much easier.
After shipping version 1.0 of the Add-on SDK and the Add-on Builder (Beta), one of our top priorities is to help developers migrate from XUL-based add-ons to Builder/SDK based add-ons, so implementing advanced add-ons will become much easier.


So if you're a XUL add-on developer, an early adopter, and are willing to participate in the development process, then now is a great time to try out the Add-on SDK and Add-on Builder and help us figure out the right set of features to enable you to make the transition.
So if you're a XUL add-on developer, an early adopter, and are willing to participate in the development process, then now is a great time to try out the Add-on SDK and Add-on Builder and help us figure out the right set of features to enable you to make the transition.
Line 61: Line 61:
If you're running Windows, [https://wiki.mozilla.org/MozillaBuild MozillaBuild], while not mandatory, will install the correct version of Python and the MSYS package, which will make it easier to work with the SDK.
If you're running Windows, [https://wiki.mozilla.org/MozillaBuild MozillaBuild], while not mandatory, will install the correct version of Python and the MSYS package, which will make it easier to work with the SDK.


''' Will the Add-on SDK and Add-on Builder (Beta) be fully integrated into Firefox? '''
''' Will the Add-on SDK be fully integrated into Firefox? '''


The Add-on SDK is a separate product from Firefox, and there are no plans to integrate its functionality directly into Firefox. However, the Add-on Builder, Add-on SDK and Firefox teams work closely to ensure Firefox provides a great set of extension capabilities for SDK APIs to expose to add-on developers.
The Add-on SDK is a separate product from Firefox, and there are no plans to integrate its functionality directly into Firefox. However, the Add-on Builder, Add-on SDK and Firefox teams work closely to ensure Firefox provides a great set of extension capabilities for SDK APIs to expose to add-on developers.
Line 97: Line 97:


The purpose of the add-on bar is to consolidate add-on buttons/icons/widgets in a known location in the browser chrome, so that users who install an add-on with a UI will know where to look for it.
The purpose of the add-on bar is to consolidate add-on buttons/icons/widgets in a known location in the browser chrome, so that users who install an add-on with a UI will know where to look for it.


''' How can I make a Widget look and behave differently in different windows? '''
''' How can I make a Widget look and behave differently in different windows? '''


Use a [https://addons.mozilla.org/en-US/developers/docs/sdk/latest/packages/addon-kit/docs/widget.html#WidgetView  <code>WidgetView</code>].
Use a [https://addons.mozilla.org/en-US/developers/docs/sdk/latest/packages/addon-kit/docs/widget.html#WidgetView  <code>WidgetView</code>].


'''  How can I have a Preferences UI/Options UI for my add-on? '''
'''  How can I have a Preferences UI/Options UI for my add-on? '''


At the moment the SDK doesn't offer a module to give you a Preferences/Options UI for your add-on. You have to build the UI yourself using the basic UI components provided.
At the moment the Add-on SDK and Add-on Builder (Beta) don't offer a module to give you a Preferences/Options UI for your add-on. You have to build the UI yourself using the basic UI components provided.


We will add a module for this in a future release of the SDK.
We will provide a module for this in future releases of the Add-on SDK and Add-on Builder.


 
''' Why can't I create Firefox toolbars using the Add-on SDK / Add-on Builder (Beta)? '''
''' Why can't I create Firefox toolbars using the SDK/Builder? '''


In the past, we haven't provided much guidance to add-on developers about how best to integrate their user interfaces into Firefox, and the add-ons manager did not make it easy for users to access an add-on's preferences. The result of this has been a proliferation of toolbars and menu items, which can lead to a cluttered and confusing user experience.
In the past, we haven't provided much guidance to add-on developers about how best to integrate their user interfaces into Firefox, and the add-ons manager did not make it easy for users to access an add-on's preferences. The result of this has been a proliferation of toolbars and menu items, which can lead to a cluttered and confusing user experience.


Therefore in the SDK, the preferred way for add-ons to expose a permanent user interface is through the Widget API, which  will ensure that the user interfaces for all add-ons default to a standard location (the add-on bar) where users will expect to see them.
Therefore in the Add-on SDK and Add-on Builder (Beta), the preferred way for add-ons to expose a permanent user interface is through the Widget API, which  will ensure that the user interfaces for all add-ons default to a standard location (the add-on bar) where users will expect to see them.
 


''' Can I add items to Firefox's menus in my add-on? '''
''' Can I add items to Firefox's menus in my add-on? '''


No you cannot. You can add items to the context menu, but not the main menu.
No you cannot. You can add items to the context menu, but not the main menu.


''' How can I customize my widget's context menu? '''
''' How can I customize my widget's context menu? '''
Line 127: Line 122:
That's not currently possible.
That's not currently possible.


 
''' My add-on needs to prompt the user to select a file. Is there a module in the Add-on Builder (Beta) / Add-on SDK to help me with this? '''
''' My add-on needs to prompt the user to select a file. Is there a module in the SDK to help me with this? '''


Not in the core set, but you can find a external file selection module in the [https://wiki.mozilla.org/Labs/Jetpack/Modules Additional Modules] page.
Not in the core set, but you can find a external file selection module in the [https://wiki.mozilla.org/Labs/Jetpack/Modules Additional Modules] page.
Line 142: Line 136:
In this architecture the main add-on code will run in the add-on process and will not have direct access to any web content.
In this architecture the main add-on code will run in the add-on process and will not have direct access to any web content.


Although this separation isn't enforced as of Firefox 5, the SDK is designed to be forward compatible with the change, so that when it happens you won't need to rewrite add-ons written using the SDK.
Although this separation isn't enforced as of Firefox 5, Add-on SDK and Add-on Builder are designed to be forward compatible with the change, so that when this happens you won't need to rewrite add-ons written using the Add-on SDK / Add-on Builder.
 


''' What's a content script? '''
''' What's a content script? '''
Line 150: Line 143:


Content scripts don't share an execution context with add-on code, so code in a content script can't directly access variables and functions in the add-on code or vice versa. Instead, you communicate between content scripts and add-on code using a message-passing scheme.
Content scripts don't share an execution context with add-on code, so code in a content script can't directly access variables and functions in the add-on code or vice versa. Instead, you communicate between content scripts and add-on code using a message-passing scheme.


''' I have a panel hosting some content, and it has a content script associated with it. Whenever the panel's location changes the content script stops working, and gives me this error: "ERR_DESTROYED, "The page has been destroyed and can no longer be used." How can I fix this? '''
''' I have a panel hosting some content, and it has a content script associated with it. Whenever the panel's location changes the content script stops working, and gives me this error: "ERR_DESTROYED, "The page has been destroyed and can no longer be used." How can I fix this? '''


The best workaround for this is to load the panel's document in an [https://developer.mozilla.org/en/HTML/Element/iframe iframe], and change that. Then the panel's content scripts will continue to work.
The best workaround for this is to load the panel's document in an [https://developer.mozilla.org/en/HTML/Element/iframe iframe], and change that. Then the panel's content scripts will continue to work.


''' How can I run a content script in the context of the currently active tab? '''
''' How can I run a content script in the context of the currently active tab? '''


Use [https://addons.mozilla.org/en-US/developers/docs/sdk/latest/packages/addon-kit/docs/tabs.html <code>tab.attach()</code>].
Use [https://addons.mozilla.org/en-US/developers/docs/sdk/latest/packages/addon-kit/docs/tabs.html <code>tab.attach()</code>].


''' How can I assign a value in a content script to a variable in my main add-on script? '''
''' How can I assign a value in a content script to a variable in my main add-on script? '''
Line 205: Line 195:
For debugging purposes you can log strings to the console using the global [https://addons.mozilla.org/en-US/developers/docs/sdk/latest/dev-guide/addon-development/console.html <code>console</code>] object.
For debugging purposes you can log strings to the console using the global [https://addons.mozilla.org/en-US/developers/docs/sdk/latest/dev-guide/addon-development/console.html <code>console</code>] object.


''' Can I use XUL in an Add-on SDK / Add-on Builder based add-on? '''


''' Can I use XUL in an SDK-based add-on? '''
Yes.  However, some of the features of the traditional XUL-based add-on platform, such a XUL overlays, are not available to Builder / SDK - based add-ons because they are incompatible with instant install/removal of add-ons or loading add-ons in separate processes.
 
Yes.  However, some of the features of the traditional XUL-based add-on platform, such a XUL overlays, are not available to SDK-based add-ons because they are incompatible with instant install/removal of add-ons or loading add-ons in separate processes.
 


''' Can I use jQuery in my add-on? '''
''' Can I use jQuery in my add-on? '''


Yes, you can. Just add it as another content script. See the 'reddit-panel' example in the SDK.
Yes, you can. Just add it as another content script. See the 'reddit-panel' example in the Add-on SDK.
 


''' Can I use other CommonJS modules like node.js in my add-on? '''
''' Can I use other CommonJS modules like node.js in my add-on? '''
Line 220: Line 207:
Not yet, although we plan to add this ability as soon as we can.
Not yet, although we plan to add this ability as soon as we can.


 
''' Can I use Add-on SDK / Add-on Builder modules in a traditional XUL extension? '''
''' Can I use SDK modules in a traditional XUL extension? '''


Not at the moment, although we hope to support this soon.
Not at the moment, although we hope to support this soon.


 
''' Is there a Socket API in the Add-on SDK? '''
''' Is there a Socket API in the SDK? '''


Not in the core set, but you can find a external sockets module in the [https://wiki.mozilla.org/Labs/Jetpack/Modules Additional Modules] page.
Not in the core set, but you can find a external sockets module in the [https://wiki.mozilla.org/Labs/Jetpack/Modules Additional Modules] page.


''' What's the local path on disk for my add-on's data directory? '''
''' What's the local path on disk for my add-on's data directory? '''
Line 236: Line 220:


The <code>require("self").data.url(name)</code> function will give you a URL that's usable from within the addon itself (e.g. as a content-script), but that involves a mapping function that goes from URLs to resources, and those resources don't have to be real files on disk.
The <code>require("self").data.url(name)</code> function will give you a URL that's usable from within the addon itself (e.g. as a content-script), but that involves a mapping function that goes from URLs to resources, and those resources don't have to be real files on disk.


''' How can I read from/write to a file? '''
''' How can I read from/write to a file? '''


You can use the file module in api-utils. However, if you just need some persistent storage  and don't need the data to be available outside your add-on, you can use the simple-storage module in addon-kit.
You can use the file module in api-utils. However, if you just need some persistent storage  and don't need the data to be available outside your add-on, you can use the simple-storage module in addon-kit.


''' How can I access data from my add-on's 'package.json' file, such as my add-on's name or version number? '''
''' How can I access data from my add-on's 'package.json' file, such as my add-on's name or version number? '''


At the moment there isn't a properly supported way to do this.
At the moment there isn't a properly supported way to do this.


''' How can I debug my add-on? '''
''' How can I debug my add-on? '''
Confirmed users
34

edits