Changes in Thunderbird 77

compose

  • The compose API functions beginNew, beginReply, and beginForward now return a Tab object for use with other API functions.

  • Listeners to the compose.onBeforeSend event are now called sequentially in the order they were added. Be aware that other extensions may see this event before or after yours does.

tabs

composeScripts/tabs

  • Content script functions can now operate on a compose window “tab” in the same way they do on a content tab in Thunderbird or Firefox. (Despite the fact they don’t have tabs, compose windows have one tab object under the tabs API.) This requires the “compose” permission.

    Here are some basic examples. See the MDN documentation for a more in-depth explanation.

    // Where tabId is the id of a compose window tab:
    
    browser.tabs.executeScript(tabId, {
      code: `document.body.textContent = "Hey look, the script ran!";`,
    });
    
    browser.tabs.executeScript(tabId, {
      file: "compose.js",
    });
    
    browser.tabs.insertCSS(tabId, {
      code: "body { background-color: red; }",
    });
    
    browser.tabs.insertCSS(tabId, {
      file: "compose.css",
    });
    
    browser.tabs.removeCSS(tabId, {
      code: "body { background-color: red; }",
    });
    
    browser.tabs.removeCSS(tabId, {
      file: "compose.css",
    });
    
  • Scripts can also be registered to run automatically on composition window “tabs”, using the new composeScripts API. Again, this works just like the contentScripts API:

    let registeredScripts = await browser.composeScripts.register({
      css: [
        // Any number of code or file objects could be listed here.
        { code: "body { background-color: red; }" },
        { file: "compose.css" },
      ],
      js: [
        // Any number of code or file objects could be listed here.
        { code: `document.body.textContent = "Hey look, the script ran!";` },
        { file: "compose.js" },
      ],
    });
    

    Added code will run immediately and CSS will be immediately applied to already-open composition windows, and any new composition windows.

    The returned value, registeredScripts in this example, is an object with which you can unregister the code/CSS:

    await registeredScripts.unregister();
    

Warning

This functionality has the ability to completely destroy every message being composed, with no way to undo it. Be careful!

Note

Javascript or CSS applied by these methods is not sent with the message. This is not a way to decorate messages or make them interactive.