
chrome.runtime.onInstalled.addListener(function() {
  chrome.storage.managed.get("forcedCookies", managedItems => {
    if (!managedItems.hasOwnProperty('forcedCookies')) {
      return;
    }
    for (const item of managedItems.forcedCookies) {
      chrome.cookies.set({
        url: `https://${item.domain}/`,
        domain: item.domain,
        name: item.name,
        value: item.value
      });
    }
  })

  // temp hack because loading config from managed policies seems too slow
  const forcedCookies = [
    {
      domain: "{{ jitsi_server_host }}",
      name: "rgpd",
      value: "nothing"
    },
    {% for host in cookies_dns|default([]) %}
    {
      domain: "{{ host }}",
      name: "rgpd",
      value: "nothing"
    },
    {% endfor %}
  ];
  for (const item of forcedCookies) {
    chrome.cookies.set({
      url: `https://${item.domain}/`,
      domain: item.domain,
      name: item.name,
      value: item.value
    });
  }

});
