user3499836
user3499836

Reputation: 117

Firefox webextension API - Kill cookies

How to kill specific cookies using the webextension API?

I can fetch the cookies using - browser.cookies.getAll({domain: cookieDomain})

But to remove cookies, I require both the url and name,

browser.cookies.remove({name: cookie.name, url: cookie.domain})

And, domain cannot be passed to url parameter to remove. Also, I don't get the url from the cookie object.

Then, how do you remove specific cookies?

Thanks.

Upvotes: 0

Views: 148

Answers (1)

Endyl
Endyl

Reputation: 68

You should be able to construct the url by concatenating cookie.domain and cookie.path, and you get the protocol by checking cookie.secure:

const cookieName = cookie.name;
const cookieProtocol = cookie.secure ? 'https://' : 'http://';
const cookieUrl = cookieProtocol + cookie.domain + cookie.path;
browser.cookies.remove({name: cookieName, url: cookieUrl}).then(
    () => {
        console.log('Removed:', cookieName, cookieUrl);
    }
).catch(
    (aReason) => {
        console.log('Failed to remove cookie', aReason);
    }
);

Upvotes: 1

Related Questions