Closed Bug 1711040 Opened 2 months ago Closed 1 month ago

Wrong content script tab ID with multiple mailTab windows

Categories

(Thunderbird :: Add-Ons: Extensions API, defect)

defect

Tracking

(thunderbird_esr78 wontfix, thunderbird90 affected)

RESOLVED FIXED
91 Branch
Tracking Status
thunderbird_esr78 --- wontfix
thunderbird90 --- affected

People

(Reporter: zephyr, Assigned: TbSync)

Details

Attachments

(2 files)

Attached file reproducer

Bug

When using content script on Thunderbird the receiver get the tab of the sender as an argument. It contains the id of the tab. When opening multiple windows the tab ID received can be wrong. Let's consider the minimal reproducer add-on below.

Reproducer

manifest.json

{
    "manifest_version": 2,
    "name": "test tabId",
    "description": "Showcase the tabId bug",
    "version": "1.0.0",
    "author": "author",
    "applications": {
        "gecko": {
            "id": "no-reply@mozilla.com",
            "strict_min_version": "78.4"
        }
    },
    "background": {
        "scripts": [
            "background.js"
        ]
    },
    "message_display_action": {
        "default_title": "Test"
    },
    "permissions": [
        "messagesModify"
    ]
}

background.js

messenger.messageDisplayScripts.register({'js': [{'file': 'content.js'}]});

messenger.runtime.onConnect.addListener((p) => {
    console.log('email tabId ', p.sender.tab.id);
    messenger.messageDisplayAction.setBadgeText({text: p.sender.tab.id.toString()});
})

content.js

messenger.runtime.connect();

Expected behavior

This should log the tab ID to the console and set the tab ID as the badge text each time a message is displayed

Actual behavior

When opening a second mailTab in a new window, the badge text is updated to the new tab id as expected. But when coming back to the first mailTab, the tab ID displayed is the id of the second tab. The tab ID received is the same for the first and second tab.

Closing the second window restore the correct behavior.

Remarks

The same wrong behavior appear when using messenger.runtime.sendMessage()

The wrong behavior only appear on mailTab and not on message tab.

The issue is present on all latest Thunderbird from all channels (release, beta, daily)

I have attach the reproducer

Is this a duplicate of 1716262?

Flags: needinfo?(geoff)

Hm, no.

Flags: needinfo?(geoff)

There's really only one instance of the mail tab per window. When you switch tabs it updates to look like the new tab. That'll be the cause.

I probably need one more pointer. I observed the following:

  • window A has mailtab (id 2) + message Tab
  • window B with mailTab (id 5) is opened and and also a message Tab, mailTab is active
  • window A is switched to message Tab and back to mailTab -> It thinks it is id5
  • window B is switched to message Tab
  • window A is switched to message Tab and back to mailTab -> Actor error, mailtab does not know its id

So the second window is somehow the only reference and its active mail tab info is used for all mail tabs in all windows. If it does not have an active mail tab, all other mail tabs fails to get any active mail tab info.

Any idea where to look?

Flags: needinfo?(geoff)

A messenger.messageDisplayAction.onClicked event always returns to correct id.

This line is returning the wrong id (always the same, regardless which mailtab it actually is)
https://searchfox.org/comm-central/rev/d022f03b903e5de8602dff4dfbb6853a696777d5/mail/components/extensions/parent/ext-mail.js#95

browser.id here:
https://searchfox.org/comm-central/rev/d022f03b903e5de8602dff4dfbb6853a696777d5/mail/components/extensions/parent/ext-mail.js#491

is just "messagepane" , so the same for all windows and thus overwritten. Could we use browser.browserId which seems to be different for different windows?

But browser.id is also used in 2 more places a few lines below, change there as well?

Assignee: nobody → john
Flags: needinfo?(geoff)
Status: UNCONFIRMED → ASSIGNED
Ever confirmed: true
Target Milestone: --- → 91 Branch

Pushed by mkmelin@iki.fi:
https://hg.mozilla.org/comm-central/rev/3740475a0254
Support multiple windows with mailTabs. r=darktrojan

Status: ASSIGNED → RESOLVED
Closed: 1 month ago
Resolution: --- → FIXED
You need to log in before you can comment on or make changes to this bug.