Tab deactivate event not fired for the first tab for the first deactivation

RESOLVED INCOMPLETE

Status

Add-on SDK
General
RESOLVED INCOMPLETE
2 years ago
3 months ago

People

(Reporter: Saithis, Unassigned)

Tracking

Firefox Tracking Flags

(Not tracked)

Details

Attachments

(1 attachment)

519 bytes, application/x-zip-compressed
Details
(Reporter)

Description

2 years ago
Created attachment 8696333 [details]
firefox-tab-deactivate-bug.zip

User Agent: Mozilla/5.0 (Windows NT 10.0; WOW64; rv:44.0) Gecko/20100101 Firefox/44.0
Build ID: 20151201004002

Steps to reproduce:

1. require "sdk/tabs"
2. attach a activate and deactivate event listener to the global tabs object and output the tab id to the console
3. run "jpm run"
4. open a new tab (here the activate event for the new tab is fired, but the deactivate event for the initial tab is not fired)
5. open another tab
6. siwtch to the first tab
7. switch to the second tab


Actual results:

Console output:

console.log: tab-deactivate-bug: activate tab: -5-2
console.log: tab-deactivate-bug: deactivate tab: -5-2
console.log: tab-deactivate-bug: activate tab: -5-3
console.log: tab-deactivate-bug: deactivate tab: -5-3
console.log: tab-deactivate-bug: activate tab: -5-1
console.log: tab-deactivate-bug: deactivate tab: -5-1
console.log: tab-deactivate-bug: activate tab: -5-2




Expected results:

Console output:

console.log: tab-deactivate-bug: deactivate tab: -5-1
console.log: tab-deactivate-bug: activate tab: -5-2
console.log: tab-deactivate-bug: deactivate tab: -5-2
console.log: tab-deactivate-bug: activate tab: -5-3
console.log: tab-deactivate-bug: deactivate tab: -5-3
console.log: tab-deactivate-bug: activate tab: -5-1
console.log: tab-deactivate-bug: deactivate tab: -5-1
console.log: tab-deactivate-bug: activate tab: -5-2
(Reporter)

Updated

2 years ago
OS: Unspecified → Windows 10
Hardware: Unspecified → x86_64
I am also having this issue.

Only difference is that I am attaching my 'deactivate' listener on the immediate activeTab itself. So:

==============================================

for (tab in tabs) {
  if (tab.url.includes('my-url.com') {
    tab.on('deactivate', deactivationHandler);
  }
}

==============================================

Steps are pretty much same as above:

1. require('sdk/tabs')
2. get tab and attach listener as seen in above snippet.
3. switch to another tab, deactivationHandler is NOT run.
4. switch back to original tab ('my-url.com').
5. switch to another tab, deactivationHandler IS run.

Build: Firefox Dev Edition version 48.0a2
OS: Linux 4.2.0-35
Dist: Ubuntu (*sigh*) 15.10

This is for the Test Pilot project. https://github.com/mozilla/testpilot/tree/master/addon
There doesn't seem to be an nsIObserver event fired when the application itself loses focus.

Suggestion for an SDK-level fix: listen globally to 'deactivate' events on all open windows (might be doing this already?). When 'deactivate' fires, check the nsIFocusManager's activeWindow property; if it's null, the application has lost focus, so fire the tab deactivate event.
Hm, it looks like there's already code listening for the window to fire an 'activate' event

https://dxr.mozilla.org/mozilla-central/source/addon-sdk/source/lib/sdk/tabs/observer.js#80

so adding a parallel 'deactivate' listener seems to make sense.
https://bugzilla.mozilla.org/show_bug.cgi?id=1399562
Status: UNCONFIRMED → RESOLVED
Last Resolved: 3 months ago
Resolution: --- → INCOMPLETE
https://bugzilla.mozilla.org/show_bug.cgi?id=1399562
You need to log in before you can comment on or make changes to this bug.