Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Google Chrome tab ID changes in tab's lifetime

I'm implementing a Google Chrome extensions that handles tabs. This includes that I fetch the onCreated, onUpdated and onActivated. Each time, I use the tabId in my logic, initially stored in an array during the handling of onCreated events. In principle, everything works fine.

However, I noticed a glitch. Occasionally, the ID of an already existing tab changes. Thus, a tab has then an ID that is not in my array, which naturally results in errors. I can reproduce this issue in the following use case:

  • open 2 or more tabs with different URLs
  • load in one tab T a URL that is already loaded in another tab

In this case, two things happen: Firstly, instead of the onUpdated event, the onActivated event for T fires. And secondly, T has now a new ID, typically incremented by 2.

This seems to me far from intuitive. I would even call it a bug. Has anybody an idea what's going here?

Any hints are much appreciated!

like image 520
Christian Avatar asked Jul 19 '13 22:07

Christian


People also ask

Why do my tabs keep changing in Chrome?

This happens because of a Chrome feature that “discards” any tabs you haven't used for some time, in order to save memory and prevent the browser or even your PC or Mac from running slow.

How do I stop Chrome from losing my tabs?

Open the Chrome menu (click the 3-dot menu in the upper-right corner of Chrome) Click Settings. Scroll to the On Startup section at the bottom of the page. Click to enable the setting Continue where you left off.

How do I get my tab back to normal?

Right-click a blank space on the tab bar at the top of the window and choose Reopen closed tab. You can also use a keyboard shortcut to accomplish this: CTRL + Shift + T on a PC or Command + Shift + T on a Mac.


1 Answers

It's likely caused by prerendering. This can be detected by listening to the chrome.webNavigation.onTabReplaced or chrome.tabs.onReplaced event. Also refer to the the webNavigation event order section for more details.

like image 77
Rob W Avatar answered Oct 17 '22 10:10

Rob W