In a chrome extension, I’ve created tab properties that I’m trying to store with each tab. What is the best way to do this? I’ve looked into using localStorage, but it seems like there could be an easier way. The data is by no means permanent, it only exists as long as the tab does.
Share
There’s definitely no need to use
localStorage. Without the notion “data is by no means permanent”, one already knows that: tab IDs are unique within a session. From this fact, it follows that the data is non-persistent.The best method to implement it is to maintain a hash of tab properties:
chrome.tabs.onCreated(optional, add initial info to tab hash)chrome.tabs.onUpdated– (Add/) Update tab hash (URL is available)chrome.tabs.onRemoved– Remove hash entryTab objects are not expensive: All properties are primitives (booleans, numbers, strings).
For instance (background page only):