summaryrefslogtreecommitdiff
path: root/src/lib/TabCache.js
blob: 16d6e1fc4ab4161b74ff54c8e69dda6143648cac (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
var TabCache = (() => {

  let cache = new Map();

  browser.tabs.onUpdated.addListener(tab => {
    cache.set(tab.id, tab);
  });

  browser.tabs.onRemoved.addListener(tab => {
    cache.delete(tab.id);
  });
  
  (async () => {
    for (let tab of await browser.tabs.query({})) {
      cache.set(tab.id, tab);
    }
  })();

  return {
    get(tabId) {
      return cache.get(tabId);
    }
  };
})();