Closed Bug 1402742 Opened 7 years ago Closed 7 years ago

attaching tab assigns new tabId, chrome.tabs.onAttached reports old one, after detaching again that tab chrome.tabs.onDetached will report old tabId

Categories

(WebExtensions :: Untriaged, defect)

57 Branch
All
Unspecified
defect
Not set
major

Tracking

(Not tracked)

RESOLVED DUPLICATE of bug 1398272

People

(Reporter: karol, Unassigned)

Details

User Agent: Mozilla/5.0 (Windows NT 6.1; WOW64; rv:58.0) Gecko/20100101 Firefox/58.0
Build ID: 20170924100550

Steps to reproduce:

make background script with:

	chrome.tabs.onAttached.addListener(function(tabId, attachInfo) {
		console.log("on attached event is reporting me tabId: "+tabId+"");
		console.log("yeah cool, lets add DOM elements with this tabId");
		chrome.tabs.get(tabId, function(tab) {
			console.log("lets pretend this is somewhere in the popup.html, now I want to refresh, my DOM elemnts, lets say favicon, lets use chrome.tabs.get... oh... weird, this tabId now magically changed to: "+tab.id+", eeeeeh what is going on? How do I relate that now to my DOM element with original tabId ?");
		});
	});
	
	chrome.tabs.onDetached.addListener(function(tabId, detachInfo) {
		console.log("on detached event is reporting me tabId: "+tabId);
		console.log("Oh wow this is not the new tabId anymore? How come?, We are back to previous? Inconsistent!");
		console.log("OMG this will not do!, now it tries to remove my DOM elements that are not there because I added them under new tabId?");
	});


Actual results:

attached tab has assigned new Id, reporting old one in chrome.tabs.onAttached.addListener

chrome.tabs.onDetached.addListener, reports original id, which is not valid anymore.


Expected results:

attached tab, should preserve original tab.id, or if tab.id was changed, chrome.tabs.onReplaced should trigger, and chrome.tabs.onDetached.addListener should report new tabId.
Severity: normal → major
Component: Untriaged → Extension Compatibility
Hardware: Unspecified → All
Component: Extension Compatibility → WebExtensions: Untriaged
Product: Firefox → Toolkit
Status: UNCONFIRMED → RESOLVED
Closed: 7 years ago
Resolution: --- → DUPLICATE
Hi, I reported this bug since I didn't find one that explains this behavior, because what Piro explained in his bug report (1398272), is not exactly correct.
He said that it happens only in registered onUpdated events, but actually what he describes is a bit misleading.

What is going on is that, moving tab between windows, causes the attached tab getting assigned a new id.

But in onAttached and onDetached events, tab id remains old one. Then when you try to do chrom.tab.get with old id, you can access that tab but inside tab.id it will have new id.

Worst problem is that later on onUpdated event will fire up with new id.
You can add chrome.get inside of onAttached and get new tabId, but it will break all overall consistency.
Especially when you have already DOM elements with old id. Problem then arises with tree structure to keep it intact between moving tabs between windows. As well as with updating/moving around/deleting attached tabs with new id, having DOM element with old one.

I need consistent tabId to retain tree structure after moving tabs between windows.
Anyway is there a way to merge bug reports? Because it's related.
Product: Toolkit → WebExtensions
You need to log in before you can comment on or make changes to this bug.