Google Chrome tab ID changes in tab's lifetime
google-chrome, google-chrome-extension, javascript
Solution
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.
Problem
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!