Re-setting tab id in chrome extension after browser restart

My Chrome extension saves some data in localStorage, and this needs to be done for each tab. Using the tab identifier that I get from the API, I can save the data as I need. Unfortunately, if the browser restarts, the tabs seem to get different identifiers, and my circuit breaks up. Is there a way to identify tabs in such a way as to survive a restart? The URL is insufficient because the same URL can appear on different tabs and should not confuse these tabs.

What is the right template for this?

+4
source share
1 answer

I also had big problems. Finally, I solved this by setting a listener for Chrome, creating a new tab. See code below:

chrome.tabs.onCreated.addListener(function(tab) { //Callback function gives you the tab that was created. var tabId = tab.id; //Or, in my case I just added it here to an array of tab ids. }); 

I personally saved an array of tab identifiers that I need, and added and removed them as needed. See this documentation for help on what to do with tabs.

0
source

Source: https://habr.com/ru/post/1437006/


All Articles