Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/smikodanic/cookie-bro
Library which helps with cookie management in the Browser environment.
https://github.com/smikodanic/cookie-bro
Last synced: 15 days ago
JSON representation
Library which helps with cookie management in the Browser environment.
- Host: GitHub
- URL: https://github.com/smikodanic/cookie-bro
- Owner: smikodanic
- License: other
- Created: 2022-08-11T15:28:26.000Z (over 2 years ago)
- Default Branch: master
- Last Pushed: 2022-08-11T16:29:46.000Z (over 2 years ago)
- Last Synced: 2024-12-19T13:32:04.059Z (21 days ago)
- Language: JavaScript
- Size: 10.7 KB
- Stars: 0
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# cookie-bro
> Library which helps with cookie management in the Browser environment.## Installation
```bash
$ npm install --save cookie-bro
```## Howto
```
HTMLJS
const cookieBro = window.cookieBro;
const cookies = cookieBro.getAll();
```## Example
A puppeteer example.```js
/*** NodeJS script ***/
// inject to Chromium browser via <script> tag
await page.addScriptTag({ path: '../index.js' }); // path to cookie-bro fileconst cookies = await page.evaluate(() => {
const cookieBro = window.cookieBro;
cookieBro.setOptions({
domain: 'adsuu.com',
path: '/',
expires: 5, // number of hours or exact date
secure: false,
httpOnly: false,
sameSite: 'strict' // 'strict' for GET and POST, 'lax' only for POST
});
return cookieBro.getAll();
});
console.log('cookies::', cookies); // _ga=GA1.2.686576916.1660229610; _gid=GA1.2.2130293818.1660229610; _gat=1
```## API
#### setOptions(cookieOpts) :void
```js
interface CookieOpts {
domain?: string;
path?: string;
expires?: number | Date; // number of hours or exact date
secure?: boolean;
httpOnly?: boolean;
sameSite?: string; // 'strict' for GET and POST, 'lax' only for POST
}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](LICENSE).