Thunderbird/Add-ons Guide 63: Difference between revisions

From MozillaWiki
Jump to navigation Jump to search
(note that https://thunderbird-webextensions.readthedocs.io/en/latest/how-to/extensions68.html is the new canonical page for this information)
(document various things I ran into while upgrading my add-on for Thunderbird 68)
Line 1: Line 1:
<big>'''Add-ons Guide for Thunderbird 63 and beyond'''</big>
<big>'''Add-ons Guide for Thunderbird 63 and beyond'''</big>


{{note|This page is now considered obsolete, see https://thunderbird-webextensions.readthedocs.io/en/latest/how-to/extensions68.html instead!|reminder}}
{{note|The documentation at https://thunderbird-webextensions.readthedocs.io/en/latest/how-to/extensions68.html is a better place to start learning about converting add-ons to run on recent Thunderbird builds. However, this page contains details about specific issues you may encounter that aren't all documented there, so this may be a useful reference as well.|reminder}}


If you have programming questions or wish to discuss the future can be posted in the mozilla.dev.apps.thunderbird newsgroup, see [[Thunderbird/CommunicationChannels#If_you.27re_a_developer|Communication Channels]].
If you have programming questions or wish to discuss the future can be posted in the mozilla.dev.apps.thunderbird newsgroup, see [[Thunderbird/CommunicationChannels#If_you.27re_a_developer|Communication Channels]].
Line 67: Line 67:
* XUL element method <tt>.removeItemAt()</tt>, replacement: <tt>.remove()</tt>, example: <tt>listElement.removeItemAt(i)</tt> -> <tt>listElement.getItemAtIndex(i).remove()</tt>
* XUL element method <tt>.removeItemAt()</tt>, replacement: <tt>.remove()</tt>, example: <tt>listElement.removeItemAt(i)</tt> -> <tt>listElement.getItemAtIndex(i).remove()</tt>
* You can also use <tt>.setUnsafeInnerHTML()</tt> or <tt>document.allowUnsafeHTML = true</tt>, as a workaround to the above, see [[Thunderbird/Add-ons_Guide_57#Removed_and_changed_in_mozilla60|here]].
* You can also use <tt>.setUnsafeInnerHTML()</tt> or <tt>document.allowUnsafeHTML = true</tt>, as a workaround to the above, see [[Thunderbird/Add-ons_Guide_57#Removed_and_changed_in_mozilla60|here]].
* The interface of <tt>AddonManager.getAddonByID</tt> has changed. It now returns a promise, so instead of calling it as <tt>AddonManager.getAddonByID(''addon_id'', ''callback_function'')</tt>, you need to call it as <tt>AddonManager.getAddonByID(''addon_id'').then(''callback_function')</tt>.


== Removed in Thunderbird 63 ==
== Removed in Thunderbird 63 ==
* XUL elements <tt>listbox</tt>, <tt>listboxitem</tt> and <tt>listcell</tt>. <br/>Replacement: <tt>richlistbox</tt> ([https://github.com/jobisoft/CategoryManager/commit/2267888be7de0d7ebe4f5b4626c48210c071b16f example migration])  
* XUL elements <tt>listbox</tt>, <tt>listboxitem</tt> and <tt>listcell</tt>. <br/>Replacement: <tt>richlistbox</tt> ([https://github.com/jobisoft/CategoryManager/commit/2267888be7de0d7ebe4f5b4626c48210c071b16f example migration])  
* XUL <tt>stringbundleset</tt> / <tt>stringbundle</tt>. You will also be unable to use the `nsIStringBundleService` interface.<br/>Replacement: Use <tt>Services.strings.createBundle(...)</tt>.<br/>In order to use stringbundles, you need to load stringbundle.js in your XUL: <tt>&lt;script type="application/x-javascript" src="chrome://global/content/elements/stringbundle.js"/&gt;</tt>, but the XUL Overlay loader takes care of this. See also [https://bugzil.la/1459743 bug 1459743]
* XUL <tt>stringbundleset</tt> / <tt>stringbundle</tt>. You will also be unable to use the `nsIStringBundleService` interface.<br/>Replacement: Use <tt>Services.strings.createBundle(...)</tt>.<br/>In order to use stringbundles, you need to load stringbundle.js in your XUL: <tt>&lt;script type="application/x-javascript" src="chrome://global/content/elements/stringbundle.js"/&gt;</tt>, but the XUL Overlay loader takes care of this. See also [https://bugzil.la/1459743 bug 1459743].
 
{{note|I am not sure the above information is correct with current Thunderbird trunk builds as of March 30, 2019. I got errors when attempting to embed <tt>stringbundle</tt> elements in XUL overlays. [[User:Jikamens|Jikamens]] ([[User talk:Jikamens|talk]]) 00:34, 31 March 2019 (UTC)}}
* <tt>mailServices.js</tt> has been renamed to <tt>MailServices.jsm</tt>. The old name keeps working for now, but you get a deprecation warning in the error console if you use the old name.
* <tt>mailServices.js</tt> has been renamed to <tt>MailServices.jsm</tt>. The old name keeps working for now, but you get a deprecation warning in the error console if you use the old name.
* Starting in Thunderbird 63, all XBL-bindings will be removed from Thunderbird. That means, that if you have a XBL=binding in your add-on that extends a binding that is removed, your binding will fail. With [https://bugzilla.mozilla.org/buglist.cgi?o1=equals&v1=1484976&f1=blocked this] query, you can see all the bugs related to de-xbl-ing Thunderbird, and see how the removal of each binding is handled.
* Starting in Thunderbird 63, all XBL-bindings will be removed from Thunderbird. That means, that if you have a XBL=binding in your add-on that extends a binding that is removed, your binding will fail. With [https://bugzilla.mozilla.org/buglist.cgi?o1=equals&v1=1484976&f1=blocked this] query, you can see all the bugs related to de-xbl-ing Thunderbird, and see how the removal of each binding is handled.
 
* A bunch of globals in the message composition window were removed: <tt>nsIMsgCompDeliverMode</tt>, <tt>nsIMsgCompSendFormat</tt>, <tt>nsIMsgCompConvertible</tt>, <tt>nsIMsgCompType</tt>, <tt>nsIMsgCompFormat</tt>, <tt>nsIAbPreferMailFormat</tt>, <tt>nsIPlaintextEditorMail</tt>, <tt>nsISupportsString</tt>, and <tt>mozISpellCheckingEngine</tt>. If you use any of these, there are available as the same names underneath <tt>Ci.</tt> (a.k.a. <tt>Components.interfaces.</tt>).
== Removed in Thunderbird 64 ==
== Removed in Thunderbird 64 ==
* XUL element <tt>colorpicker</tt>.<br/>Replacement: HTML <tt>input type=color</tt>
* XUL element <tt>colorpicker</tt>.<br/>Replacement: HTML <tt>input type=color</tt>
Line 79: Line 82:
== Removed in Thunderbird 65 ==
== Removed in Thunderbird 65 ==
* XUL element <tt>progressmeter</tt>.<br/>Replacement: HTML <tt>progress</tt> ([https://github.com/jobisoft/CategoryManager/commit/be23d9abfba29e5585d485348d84bd36c3c6bcaf example migration])
* XUL element <tt>progressmeter</tt>.<br/>Replacement: HTML <tt>progress</tt> ([https://github.com/jobisoft/CategoryManager/commit/be23d9abfba29e5585d485348d84bd36c3c6bcaf example migration])
* There is no longer a <tt>statusbar</tt> element. Instead of putting <tt>statusbar</tt> elements inside a <tt>statusbarpanel</tt> in your XUL, they need to go inside an <tt>hbox</tt>. The <tt>hbox</tt> contains have the same names as the old <tt>statsusbar</tt> containers, so you just need to change the element type. Also, if your status bar items had popup menus attached to them, you will need to do that differently now as well. See [https://github.com/jikamens/send-later/blob/664468e4c29ba435edfeba8524d19a37a47dfda5/chrome/content/backgrounding.xul#L9 this example].


== Changes in Thunderbird 67 ==
== Changes in Thunderbird 67 ==
* Thunderbird no longer passes in the <tt>aContext</tt> argument to the <tt>onDataAvailable</tt> methods of stream listeners, so stream listeners need to be updated so that they no longer expect this argument.
* <tt>MailUtils.getFolderForUri</tt> was renamed to <tt>MailUtils.getExistingFolder</tt>.
==== Importing javascript modules ====
==== Importing javascript modules ====
A major backwards-incompatible change was made to importing javascript modules. Where once you used any of these:
A major backwards-incompatible change was made to importing javascript modules. Where once you used any of these:

Revision as of 00:37, 31 March 2019

Add-ons Guide for Thunderbird 63 and beyond

Note: The documentation at https://thunderbird-webextensions.readthedocs.io/en/latest/how-to/extensions68.html is a better place to start learning about converting add-ons to run on recent Thunderbird builds. However, this page contains details about specific issues you may encounter that aren't all documented there, so this may be a useful reference as well.

If you have programming questions or wish to discuss the future can be posted in the mozilla.dev.apps.thunderbird newsgroup, see Communication Channels.

Supported extension types

The following extension types are supported in from Thunderbird 63 and beyond:

WebExtensions

This is the same type of addon that Firefox currently uses. For a general introduction, see WebExtensions and What are WebExtensions.

However, the APIs are necessarily different between Thunderbird and Firefox. Some applicable Firefox APIs work in Thunderbird (just try it), other Firefox APIs do not work, and Thunderbird has a few Thunderbird-specific APIs added. There is some documentation for the Thunderbird WebExtension APIs. For any API that is not yet provided, WebExtension Experiments can be used.

There are not many WebExtensions for Thunderbird yet, so you're in new territory. Don't expect a smooth ride. But being a pioneer can be exciting, too. Help wanted!

Details: WebExtensions have a manifest.json. As documented on Thunderbird WebExtension APIs, the following WebExtension APIs are available in Thunderbird:

Bootstrapped extensions

Bootstrapped/restartless extensions with an install.rdf manifest. The code to handle bootstrapped extension and install.rdf has been moved to comm-central in bug 1510097 and should be stable now. Important: Bootstrapped legacy extensions continue to work without a manifest.json file and will in fact break if you add that file.

"Legacy" XUL extensions with overlays

"Legacy" XUL extensions with overlays are still "somewhat" supported in Thunderbird 63 and beyond. An inbuilt overlay loader will load XUL overlays for extensions but may cause graphical glitches or malfunctions. We're tracking this in bug 1476259.

Warning: Scripts in overlays are now run after all elements have been inserted into the document. This may cause unexpected behavior if your script previously ran before elements were inserted. For elements with event handlers these event handlers may run when the element is added, and they may fail if they rely on content being set up by a script which now runs after the creation of the element.

To use this overlay loader, XUL overlay legacy extensions must replace install.rdf file with a WebExtensions style manifest.json file, which includes the key "legacy" set to true. See Lightning as an example:
https://hg.mozilla.org/comm-central/rev/e81f4b59a00a7d3e18d50fd3851ecbd47762a186#l2.5 (Note: In this changeset the @variables@ are build variables, add-ons need to use fixed strings).
If your add-on has options specified in install.rdf, you need to put this in the manifest.json also. To do this, add the file to the key "legacy" instead of the value true in the following way:

{
  
  "legacy" : {
    "options" : {
      "page" : "chrome://[path to your options.xul]",
      "open_in_tab" : true/false
    }
  }
}

The key open_in_tab is optional and defaults to value false. Value true corresponds to optionsType 3 in install.rdf.

Examples of extensions converted to this type (as of 3rd December 2018):

  • Mail Redirect (version on ATN includes a good example of a working manifest.json)
  • "Lightning"
  • "Compact Header"
  • "Signature Switch"
  • "ThunderHTMLedit"

Removed in Thunderbird 60

Overlays have been progressively removed starting from this version. By version 63, there are no overlays left in Thunderbird. Due to Thunderbird's own overlay loader, XUL add-ons can still use overlays, but they can of course not overlay the removed Thunderbird overlays any more. For example, if your add-on overlaid mailWindowOverlay.xul, that needs to be changed; in this example you most likely need to overlay messenger.xul now.

Removed in Thunderbird 61

  • XUL element method .insertItemAt(), replacement: .insertBefore()
  • XUL element method .removeItemAt(), replacement: .remove(), example: listElement.removeItemAt(i) -> listElement.getItemAtIndex(i).remove()
  • You can also use .setUnsafeInnerHTML() or document.allowUnsafeHTML = true, as a workaround to the above, see here.
  • The interface of AddonManager.getAddonByID has changed. It now returns a promise, so instead of calling it as AddonManager.getAddonByID(addon_id, callback_function), you need to call it as AddonManager.getAddonByID(addon_id).then(callback_function').

Removed in Thunderbird 63

  • XUL elements listbox, listboxitem and listcell.
    Replacement: richlistbox (example migration)
  • XUL stringbundleset / stringbundle. You will also be unable to use the `nsIStringBundleService` interface.
    Replacement: Use Services.strings.createBundle(...).
    In order to use stringbundles, you need to load stringbundle.js in your XUL: <script type="application/x-javascript" src="chrome://global/content/elements/stringbundle.js"/>, but the XUL Overlay loader takes care of this. See also bug 1459743.
Note: I am not sure the above information is correct with current Thunderbird trunk builds as of March 30, 2019. I got errors when attempting to embed stringbundle elements in XUL overlays. Jikamens (talk) 00:34, 31 March 2019 (UTC)
  • mailServices.js has been renamed to MailServices.jsm. The old name keeps working for now, but you get a deprecation warning in the error console if you use the old name.
  • Starting in Thunderbird 63, all XBL-bindings will be removed from Thunderbird. That means, that if you have a XBL=binding in your add-on that extends a binding that is removed, your binding will fail. With this query, you can see all the bugs related to de-xbl-ing Thunderbird, and see how the removal of each binding is handled.
  • A bunch of globals in the message composition window were removed: nsIMsgCompDeliverMode, nsIMsgCompSendFormat, nsIMsgCompConvertible, nsIMsgCompType, nsIMsgCompFormat, nsIAbPreferMailFormat, nsIPlaintextEditorMail, nsISupportsString, and mozISpellCheckingEngine. If you use any of these, there are available as the same names underneath Ci. (a.k.a. Components.interfaces.).

Removed in Thunderbird 64

  • XUL element colorpicker.
    Replacement: HTML input type=color

Removed in Thunderbird 65

  • There is no longer a statusbar element. Instead of putting statusbar elements inside a statusbarpanel in your XUL, they need to go inside an hbox. The hbox contains have the same names as the old statsusbar containers, so you just need to change the element type. Also, if your status bar items had popup menus attached to them, you will need to do that differently now as well. See this example.

Changes in Thunderbird 67

  • Thunderbird no longer passes in the aContext argument to the onDataAvailable methods of stream listeners, so stream listeners need to be updated so that they no longer expect this argument.
  • MailUtils.getFolderForUri was renamed to MailUtils.getExistingFolder.

Importing javascript modules

A major backwards-incompatible change was made to importing javascript modules. Where once you used any of these:

Components.utils.import("resource://foo/modules/Foo.jsm");
// or…
Cu.import("resource://foo/modules/Foo.jsm");
// or…
ChromeUtils.defineModuleGetter(this, "Foo", "resource://foo/modules/Foo.jsm");

// or the two-argument variation:
var { Foo } = Cu.import("resource://foo/modules/Foo.jsm", null);
// or…
var scope = {}; Cu.import("resource://foo/modules/Foo.jsm", scope); // scope.Foo…

You should now do this:

var { Foo } = ChromeUtils.import("resource://foo/modules/Foo.jsm");
// or…
var scope = ChromeUtils.import("resource://foo/modules/Foo.jsm"); // scope.Foo…

ChromeUtils.import is a replacement for Components.utils.import (which was also changed) in this way. Note that no second argument is supplied. The returned object is a dictionary of only the objects listed in EXPORTED_SYMBOLS.

Editable menulists

The standard XUL element menulist no longer supports the editable attribute. However, editable menulists have been re-implemented using a custom element. To be able to use it, one has to include menulist.css and customElements.js:

<?xml version="1.0"?>
<?xml-stylesheet href="chrome://messenger/content/menulist.css" type="text/css"?>

...

<script type="application/javascript" src="chrome://messenger/content/customElements.js"/>

...

<menulist is="menulist-editable" editable="true">
  <menupopup>
    <menuitem label="Label1" />
  </menupopup>
</menulist>

...

To be able to use this custom element from JS, the following is needed (in addition to the includes mentioned above):

let menulist = document.createElement("menulist", { is : "menulist-editable"});
menulist.setAttribute("is", "menulist-editable");
menulist.setAttribute("editable", "true");

See also

More information about updating extensions for Thunderbird 68 can be found here.