Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
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);
}
}
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 = (
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({
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);
}
function removeAffiliatesCookies(cookie, domain) {
var cookieProtocol
cookie.secure ? (cookieProtocol = "https://") : (cookieProtocol = "http://")
browser.cookies.remove({
url: cookieProtocol + domain + cookie.path,
name: cookie.name
})
}
async get() {
return browser.cookies.get(await getCookiesQuery({
name: 'oil_data',
url: this.tab.url,
storeId: this.tab.cookieStoreId,
}, this.tab.url));
}
}
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
})
}
}
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
})
}
}