cookie-bro
Library which helps with cookie management in the Browser environment.
Installation
$ npm install --save cookie-bro
Howto
HTML
<script src="node_modules/cookie-bro/index.js">
JS
const cookieBro = window.cookieBro;
const cookies = cookieBro.getAll();
Example
A puppeteer example.
await page.addScriptTag({ path: '../index.js' });
const cookies = await page.evaluate(() => {
const cookieBro = window.cookieBro;
cookieBro.setOptions({
domain: 'adsuu.com',
path: '/',
expires: 5,
secure: false,
httpOnly: false,
sameSite: 'strict'
});
return cookieBro.getAll();
});
console.log('cookies::', cookies);
API
setOptions(cookieOpts) :voids
interface CookieOpts {
domain?: string;
path?: string;
expires?: number | Date;
secure?: boolean;
httpOnly?: boolean;
sameSite?: string;
}
setoptions(cookieOpts:CookieOpts)
put(name:string, value:string) :void
Set the cookie. Cookie value must be a string.
putObject(name:string, value:object) :void
Set the cookie. Cookie value is object.
getAll() :string
Get all cookies in string format cook1=jedan1; cook2=dva2;
get(name:string) :string
Get a cookie by specific name. Returned value is string.
getObject(name:string) :object
Get a cookie by specific name. Returned value is object of parsed value.
remove(name:string) :void
Remove cookie by specific name.
removeAll() :void
Remove all cookies.
exists(name:string) :boolean
Check if cookie exists.
License
The software licensed under AGPL-3.