How to use the webextension-polyfill.cookies function in webextension-polyfill

To help you get started, we’ve selected a few webextension-polyfill examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github cliqz-oss / re-consent / src / autoclicker.js View on Github external
async reset() {
    const url = new URL(this.tab.url);

    // TODO: This only works on Firefox
    if (browser.browsingData) {
      await browser.browsingData.removeCookies({
        hostnames: [url.hostname],
      });
      await browser.browsingData.removeLocalStorage({
        hostnames: [url.hostname],
      });
    }
    const cookies = await browser.cookies.getAll({
      url: url.href,
      firstPartyDomain: '',
    });
    const deletions = cookies.map((cki) => {
      return browser.cookies.remove({
        firstPartyDomain: '',
        name: cki.name,
        url: url.href,
      });
    });
    await Promise.all(deletions);
    await this.saveActionPreference('site', POPUP_ACTIONS.ASK);
    autoconsent.removeTab(this.tab.id);
    browser.tabs.reload(this.tab.id);
  }
}
github cliqz-oss / re-consent / src / consent / storages.js View on Github external
async getConsentCookies() {
    const cookiesQuery = await getCookiesQuery({ storeId: this.tab.cookieStoreId }, this.tab.url);
    const cookies = await browser.cookies.getAll(cookiesQuery);
    const { consentData } = this.consent.consentData;

    let consentCookies = cookies.filter(c => c.value.startsWith(consentData));

    if (consentCookies.length === 0) {
      consentCookies = cookies.filter(c => this.tab.url.indexOf(c.domain) > -1 && c.name.toLowerCase() === 'euconsent');
    }

    if (await isThirdPartyIsolateEnabled()) {
      // if third party isolation is on, the previous query will have only got third-party cookies
      const firstPartyCookiesQuery = await getCookiesQuery({
        url: this.tab.url,
        storeId: this.tab.cookieStoreId,
      }, this.tab.url);

      const firstPartyCookies = (
github cliqz-oss / re-consent / src / census.js View on Github external
async function consentCensus() {
  const cookies = await browser.cookies.getAll({});
  const consentCookies = cookies.filter((c) => {
    try {
      c.consent = new ConsentString(c.value);
      return !!c.value && (c.consent.cmpVersion === 1 || c.consent.cmpVersion === 2);
    } catch (e) {
      return false;
    }
  }).map(c => ({
    site: c.domain,
    name: c.name,
    allowedPurposes: c.consent.getPurposesAllowed().length,
    allowedVendors: c.consent.getVendorsAllowed().length,
    cmpId: c.consent.cmpId,
  }));
  console.log('[Census]', consentCookies);
  sendAnonymousTelemetry({
github cliqz-oss / re-consent / src / consent / storages.js View on Github external
async function updateCookie(cookie, newValue) {
  const newCookie = {
    expirationDate: cookie.expirationDate,
    domain: cookie.domain.startsWith('.') ? cookie.domain : undefined,
    httpOnly: cookie.httpOnly,
    name: cookie.name,
    path: cookie.path,
    secure: cookie.secure,
    storeId: cookie.storeId,
    url: `${cookie.httpOnly ? 'http' : 'https'}://${cookie.domain.startsWith('.') ? cookie.domain.substring(1) : cookie.domain}${cookie.path}`,
    value: newValue,
  };
  if (await isThirdPartyIsolateEnabled()) {
    newCookie.firstPartyDomain = cookie.firstPartyDomain || '';
  }
  return browser.cookies.set(newCookie);
}
github Altruisto / altruisto / src / background / deactivate-monetizing.js View on Github external
function removeAffiliatesCookies(cookie, domain) {
  var cookieProtocol
  cookie.secure ? (cookieProtocol = "https://") : (cookieProtocol = "http://")

  browser.cookies.remove({
    url: cookieProtocol + domain + cookie.path,
    name: cookie.name
  })
}
github cliqz-oss / re-consent / src / consent / storages.js View on Github external
async get() {
    return browser.cookies.get(await getCookiesQuery({
      name: 'oil_data',
      url: this.tab.url,
      storeId: this.tab.cookieStoreId,
    }, this.tab.url));
  }
}
github waynecz / dadda-translate-crx / src / services / shanbay.ts View on Github external
descriptor.value = async function() {
    const cookie = await browser.cookies.get({
      url: SHANBAY_HOST,
      name: 'auth_token'
    })

    if (cookie) {
      return originalMethod()
    } else {
      return browser.tabs.create({
        url: shanbayLoginURL
      })
    }
  }
github waynecz / dadda-translate-crx / src / services / youdao.ts View on Github external
descriptor.value = async function() {
    const cookie = await browser.cookies.get({
      url: YOUDAO_HOST,
      name: 'DICT_SESS'
    })

    if (cookie) {
      return originalMethod()
    } else {
      return browser.tabs.create({
        url: YOUDAo_LOGIN_URL
      })
    }
  }