How to write a Thunderbird extension (webextension) to modify the message display?

心已入冬 提交于 2020-01-15 11:36:09

问题


I'd like to write an extension for Thunderbird that modifies the message display (e.g. insert/replace text/markup/image).
Unfortunately, the documentation is lacking (due to recent changes?).

  • https://developer.mozilla.org/en-US/docs/Mozilla/Thunderbird/Thunderbird_extensions
    is outdated

  • https://developer.thunderbird.net/
    does not have useful examples (yet)

  • https://thunderbird-webextensions.readthedocs.io/
    no examples either

Some examples can be found at

  • https://github.com/thundernest/sample-extensions

Building on https://github.com/thundernest/sample-extensions/tree/master/messageDisplay

I've modified background.js

browser.messageDisplay.onMessageDisplayed.addListener((tabId, message) => {
  console.log(`Message displayed in tab ${tabId}: ${message.subject}`);
  console.log(message.id);
  browser.messages.getFull(message.id).then((messagepart) => {
      console.log(messagepart);
      body = messagepart['parts'][0]['parts'][0]['body'];
      console.log(body);
      body += "modified!";
      console.log(body);
  });
  browser.windows.getCurrent().then((window)=>{
    console.log(window.type);
  });

  browser.tabs.getCurrent().then((tab)=>{
    console.log("tab",tab);
  });
});

which gives me the message body (using magic indexes) but expectedly, the change is not reflected in the message display.
The window type returned is normal, not messageDisplay.
The tab is undefined despite adding permissions

  "permissions": [
    "messagesRead",
    "activeTab",
    "tabs",
    "tabHide"
  ],

but I assume that's because the script is running as background.

So I'd need a script running on the content / access to the tab and then some hints on how to modify the displayed message content (I do not want to modify the message).

Where would I find the equivalent documentation to

  • https://developer.mozilla.org/en-US/docs/Mozilla/Add-ons/WebExtensions/manifest.json/content_scripts

specific to Thunderbird?


Specifying content_scripts in manifest.json causes "Error: Error reloading addon messageDisplay@sample.extensions.thunderbird.net: undefined".

executeScript() from background does not seem to work either, even with tabId specified.

来源:https://stackoverflow.com/questions/59547118/how-to-write-a-thunderbird-extension-webextension-to-modify-the-message-displa

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!