tabs.onCreated and onRemoved are evaluated at different times

NEW
Unassigned

Status

()

Toolkit
WebExtensions: General
P5
normal
2 months ago
11 days ago

People

(Reporter: dietrich, Unassigned)

Tracking

unspecified
Points:
---

Firefox Tracking Flags

(firefox57 wontfix)

Details

(Whiteboard: [tabs])

(Reporter)

Description

2 months ago
57.0a1 (2017-09-04) (64-bit) Mac OS X

Listeners for onCreated event are called after the action occurs.

Listeners for the onRemoved event are called before the action occurs.

For example, given the following code:

function dumpTabCount() {
  browser.tabs.query({}).then(function(tabs) {
    console.log('TABS', tabs.length);
  }); 
}

browser.tabs.onCreated.addListener(dumpTabCount);
browser.tabs.onRemoved.addListener(dumpTabCount);


To illustrate, here's a log of what happens with the code above and a browser with one tab open:

<add a tab (2 tabs)>
2
<add a tab (3 tabs)>
3
<remove a tab (2 tabs)>
3
<remove a tab (1 tab)>
2

Comment 1

2 months ago
Could you quickly try this in Chrome and tell us what it does there?
(Reporter)

Comment 2

2 months ago
Bob is looking at tab event ordering vs Chrome in bug 1366290 so ni?ing him to see if he knows.
Flags: needinfo?(bob.silverberg)
This is a different issue from bug 1366290, which is just about the order in which tabs.onActivated and tabs.onRemoved are fired. I checked Chrome and it does have a different behaviour from Firefox, and what I believe is the correct behaviour. The above code does not include the removed tab in the output from onRemoved in Chrome.

As this is a different issue it should remain its own bug, anb does seem like something we should fix.
Flags: needinfo?(bob.silverberg)

Updated

a month ago
status-firefox57: --- → wontfix
Priority: -- → P5
Whiteboard: [tabs]
You need to log in before you can comment on or make changes to this bug.