Closed Bug 1405249 Opened 4 years ago Closed 3 years ago

Need for tab/session on restored event

Categories

(WebExtensions :: Untriaged, enhancement, P5)

56 Branch
enhancement

Tracking

(Not tracked)

RESOLVED DUPLICATE of bug 1413263

People

(Reporter: baptiste.themine, Unassigned)

References

(Blocks 1 open bug)

Details

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

Steps to reproduce:

When I restore a tab from History panel, the event browser.tabs.onCreated is triggered, however when I click the "Restore previous session" button, tabs are created/restored but this event is not triggered. Moreover, there is neither browser.tabs.onRestored nor browser.sessions.onRestored in order to know if these tabs are created/restored.
See on https://discourse.mozilla.org/t/webextensions-issue-with-tab-on-created-event/


Actual results:

There is no existing method to detect if tabs are created/restored by restoring the previous session.


Expected results:

The event browser.tabs.onCreated should be triggered when tabs are created/restored by restoring the previous session. A better solution should be to implement an event browser.tabs.onRestored or browser.sessions.onRestored.
Status: UNCONFIRMED → RESOLVED
Closed: 4 years ago
Component: Untriaged → WebExtensions: Untriaged
Product: Firefox → Toolkit
Resolution: --- → DUPLICATE
Duplicate of bug: 1364019
I am not sure it is really a duplicate of https://bugzilla.mozilla.org/show_bug.cgi?id=1364019
It involves a tab restored from history and, according to the replies, the event browser.tabs.onCreated is triggered followed by browser.webNavigation.onCommited which permits to identify if the tab is restored. But in my case, which involves restoring a previous session, the event browser.tabs.onCreated is NOT triggered at all !
(In reply to baptiste.themine from comment #2)
> I am not sure it is really a duplicate of
> https://bugzilla.mozilla.org/show_bug.cgi?id=1364019
> It involves a tab restored from history and, according to the replies, the
> event browser.tabs.onCreated is triggered followed by
> browser.webNavigation.onCommited which permits to identify if the tab is
> restored. But in my case, which involves restoring a previous session, the
> event browser.tabs.onCreated is NOT triggered at all !

But bug 1372442 seems fixed. I can't check this due to terminating the Firefox process does not seem to take me to restore session in Fx56.
This is strange, I tested the following code below on Firefox 56 yesterday :

browser.tabs.onCreated.addListener(function(tab){
    console.log("test");
});

Test step by step :
1. I load the add-on in about:debugging
2. I open the browser console
3. I close Firefox main window
4. I open Firefox
--> "test" is printed in the console, this is the page about:home
5. I click on the button "Restore previous session"
--> the page about:home is closed and other tabs are restored, nothing is printed in the console

The same behaviour occured with my signed add-on on https://addons.mozilla.org/fr/firefox/addon/popupfilteraddon
The source code is available on GitHub on https://github.com/Baptistou/PopupFilter
My add-on display the count of open tabs. When a tab is created, inside browser.tabs.onCreated, the tab is pushed into an array so the count is incremented by one. When a tab is closed, inside browser.tabs.onRemoved, the tab is removed from array so the count is decremented by one.

Test step by step :
1. I open Firefox
--> open tabs = 1, this is the page about:home
2. I click on the button "Restore previous session"
--> open tabs = 0, onRemoved is triggered, not onCreated
I can provide screenshots if necessary.
I just tried again the steps as above. After several tests with different kind of tabs closed, then session restored, I found that browser.tabs.onCreated is not triggered with about:* pages but it is triggered with http://* pages.
Status: RESOLVED → UNCONFIRMED
Resolution: DUPLICATE → ---
This is so weird, the issue seems to appeared randomly.
- If we closed Firefox with last focus given to the first tab then we restore session, browser.tabs.onCreated is triggered for every tabs but not the first.
- If we closed Firefox with last focus given to the second/third/fourth... tab, browser.tabs.onCreated is triggered only for the last tab.
- If we closed Firefox with last focus given to the last tab, browser.tabs.onCreated is not triggered at all.
It was not related to the url of tabs. I am totally confused...
Severity: normal → enhancement
Priority: -- → P5
Summary: WebExtension : Need for tab/session on restored event → Need for tab/session on restored event
Product: Toolkit → WebExtensions
Blocks: 1476144
No longer blocks: Session_managers
Status: UNCONFIRMED → RESOLVED
Closed: 4 years ago3 years ago
Resolution: --- → DUPLICATE
Duplicate of bug: 1413263
You need to log in before you can comment on or make changes to this bug.