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:
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!
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.
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.
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.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With