summaryrefslogtreecommitdiff
path: root/fig-frontend-client/extension/background.js
blob: a0f4c91b642f9d10e79d77e8276da53b8eb917c4 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
/* Retrieve any previously set cookie and send to content script */

function getActiveTab() {
  return browser.tabs.query({active: true, currentWindow: true});
}

function cookieUpdate() {
  getActiveTab().then((tabs) => {
    // get any previously set cookie for the current tab 
    let gettingCookies = browser.cookies.get({
      url: tabs[0].url,
      name: "name"
    });
    gettingCookies.then((cookie) => {
      browser.tabs.sendMessage(tabs[0].id, cookie.value);
    });
  }); 
}

// update when the tab is updated
browser.tabs.onUpdated.addListener(cookieUpdate);
// update when the tab is activated
browser.tabs.onActivated.addListener(cookieUpdate);