Bug 1674932 Comment 0 Edit History

Note: The actual edited comment in the bug view page will always show the original commenter’s name and original timestamp.

### Bug

The `messageDisplayScripts` display API was introduced in Thunderbird 82 and then backported to ESR 78.4, see https://bugzilla.mozilla.org/show_bug.cgi?id=1504475.

On Thunderbird 82, the API works fine.

On Thunderbird 78.4, registering a content script with `messageDisplayScripts.register()` does not always behave as expected. Let's consider the minimal reproducer add-on below.

### Reproducer

manifest.json
```json
{
  "manifest_version": 2,
  "applications": {
    "gecko": {
      "id": "test@thunder.bird",
      "strict_min_version": "78.4.0"
    }
  },
  "name": "test",
  "version": "1.0.0",
  "permissions": [
    "messagesModify"
  ],
  "background": {
    "scripts": [
      "background.js"
    ]
  }
}
```
background.js
```javascript
browser.messageDisplayScripts.register({
    js: [{
        file: "content.js",
    }]
});

```
content.js
```javascript
console.info("Test content script executed");
```
### Expected behaviour

This should log the string to the console each time a message is displayed in Thunderbird.

### Actual behaviour

After this add-on has been installed on Thunderbird 78.4, we can observe that:

* The string is not logged to the console when displaying messages in the main 3-pane window. No error is printed.
* When opening messages in a new window, by right-clicking either on the email account (left panel) or on a message in the list, then the add-on works in the new window and the string is logged when messages are displayed in this new window. For the old window, observations may differ: I observed that the add-on is still not working, but that displaying messages would now log an error (`uncaught exception: Object`) instead of remaining silent. Another user reported that the content script would also work in the first window after opening a new one.
* When changing the layout (classic/wide/vertical) of the main window, then the add-on works (and keeps working if switching back to the initial layout). But this manipulation needs to be done each time Thunderbird is restarted.
* Under certain conditions (Not sure which ones, this has been observed with a more complex add-on), the add-on produces a slightly more verbose error message: `uncaught exception: Object 2 ext-extensionScripts.js:161:12`.

This was tested on fresh profiles, on Linux and MacOS.

### Remarks

To me it looks like something in the main 3-pane window is not initialised as it should be, and this would cause the content script injection to break. Changing the window layout apparently fixes that.

The issue is not present on Thunderbird 82, so there is a good chance this bug has been fixed already, but it may be desirable to identify the fix and to backport it to ESR 78.4+ for the `messageDisplayScripts` to work as expected.

This issue was reported on the GitHub repository for an add-on, [here](https://github.com/Qeole/colorediffs/pull/94#issuecomment-716419134) and [there](https://github.com/Qeole/colorediffs/issues/95).
### Bug

The `messageDisplayScripts` display API was introduced in Thunderbird 82 and then backported to ESR 78.4, see bug 1504475.

On Thunderbird 82, the API works fine.

On Thunderbird 78.4, registering a content script with `messageDisplayScripts.register()` does not always behave as expected. Let's consider the minimal reproducer add-on below.

### Reproducer

manifest.json
```json
{
  "manifest_version": 2,
  "applications": {
    "gecko": {
      "id": "test@thunder.bird",
      "strict_min_version": "78.4.0"
    }
  },
  "name": "test",
  "version": "1.0.0",
  "permissions": [
    "messagesModify"
  ],
  "background": {
    "scripts": [
      "background.js"
    ]
  }
}
```
background.js
```javascript
browser.messageDisplayScripts.register({
    js: [{
        file: "content.js",
    }]
});

```
content.js
```javascript
console.info("Test content script executed");
```
### Expected behaviour

This should log the string to the console each time a message is displayed in Thunderbird.

### Actual behaviour

After this add-on has been installed on Thunderbird 78.4, we can observe that:

* The string is not logged to the console when displaying messages in the main 3-pane window. No error is printed.
* When opening messages in a new window, by right-clicking either on the email account (left panel) or on a message in the list, then the add-on works in the new window and the string is logged when messages are displayed in this new window. For the old window, observations may differ: I observed that the add-on is still not working, but that displaying messages would now log an error (`uncaught exception: Object`) instead of remaining silent. Another user reported that the content script would also work in the first window after opening a new one.
* When changing the layout (classic/wide/vertical) of the main window, then the add-on works (and keeps working if switching back to the initial layout). But this manipulation needs to be done each time Thunderbird is restarted.
* Under certain conditions (Not sure which ones, this has been observed with a more complex add-on), the add-on produces a slightly more verbose error message: `uncaught exception: Object 2 ext-extensionScripts.js:161:12`.

This was tested on fresh profiles, on Linux and MacOS.

### Remarks

To me it looks like something in the main 3-pane window is not initialised as it should be, and this would cause the content script injection to break. Changing the window layout apparently fixes that.

The issue is not present on Thunderbird 82, so there is a good chance this bug has been fixed already, but it may be desirable to identify the fix and to backport it to ESR 78.4+ for the `messageDisplayScripts` to work as expected.

This issue was reported on the GitHub repository for an add-on, [here](https://github.com/Qeole/colorediffs/pull/94#issuecomment-716419134) and [there](https://github.com/Qeole/colorediffs/issues/95).

Back to Bug 1674932 Comment 0