We recommend that you read the Getting started with Kameleo Automation article before reading this one.
Accessing cookies to export them to a .json file or importing cookies from another system to a Kameleo virtual browser profile can be useful. You won’t have to deal with different browser APIs you can simply use Kameleo Local API to do it.
You can export, import, or delete cookies of any virtual browser profile that is in terminated state. So it has been started at least once, but currently not running.
In this example we show how to list cookies, then modify a cookie and then delete all cookies.
Adding a cookie for a domain will override all the cookies for the given domain.
-
const cookieList = await client.listCookies(profile.id); const newCookie = cookieList[0]; newCookie.value = '123'; const cookiesArray = new Array(newCookie); await client.addCookies(profile.id, { body: cookiesArray }); await client.deleteCookies(profile.id);
See full example here.
-
var cookieList = await client.ListCookiesAsync(profile.Id); var newCookie = cookieList[0]; newCookie.Value = "123"; var cookiesArray = new List<CookieRequest> {new CookieRequest(newCookie)}; await client.AddCookiesAsync(profile.Id, cookiesArray); await client.DeleteCookiesAsync(profile.Id);
See full example here.
-
cookie_list = client.list_cookies(profile.id) cookie = cookie_list[0] new_cookie = CookieRequest(domain=cookie.domain, name=cookie.name, path=cookie.path, value=cookie.value, host_only=cookie.host_only, http_only=cookie.http_only, secure=cookie.secure, same_site=cookie.same_site, expiration_date=cookie.expiration_date) cookie_array = [new_cookie] client.add_cookies(profile.id, body=cookie_array) client.delete_cookies(profile.id)
See full example here.