-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* remove tldjs * refactor firefox cookies * refactor chrome * Update ChromeMacosCookieProvider.ts * lint * remove getIterations * refactor * Create ChromeMacosCookieProvider.unit.test.ts * Update ChromeMacosCookieProvider.unit.test.ts * Create ChromeWindowsCookieProvider.unit.test.ts * bump version to 1.0, add homepage link * Update package.json * 1.0 docs (#17) * docs update * Create browser_profiles.md * Update index.md * Create favicon.ico
- Loading branch information
1 parent
713f162
commit b4c0a5b
Showing
29 changed files
with
523 additions
and
308 deletions.
There are no files selected for viewing
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
--- | ||
layout: default | ||
title: Browser profiles | ||
nav_order: 4 | ||
description: Specifying browser profiles | ||
permalink: /browser-profiles | ||
--- | ||
|
||
# Browser profiles | ||
|
||
## Choosing browser profiles | ||
|
||
If you are utilising multiple browser profiles, you can specify which one to use in the function options. | ||
|
||
```js | ||
import { getCookie, listCookies, Browser } from 'cookie-thief'; | ||
|
||
await getCookie({ | ||
browser: Browser.Chrome, | ||
cookieName: 'foo', | ||
domain: '.github.com', | ||
options: { | ||
profile: 'SomeProfile', | ||
}, | ||
}); | ||
|
||
await listCookies({ | ||
browser: Browser.Firefox, | ||
options: { | ||
profile: 'SomeProfile', | ||
}, | ||
}); | ||
``` | ||
|
||
## Listing browser profiles | ||
|
||
If you want to programmatically list browser profiles, you can with `listProfiles`. | ||
|
||
```js | ||
import { listProfiles, Browser } from 'cookie-thief'; | ||
|
||
const profiles: string[] = await listProfiles(Browser.Chrome); | ||
``` | ||
|
||
## Default browser profiles | ||
|
||
If you do not specify a profile, a default profile name will be used. | ||
|
||
* Firefox: `default-release` | ||
* Chrome: `Default` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
--- | ||
layout: default | ||
title: Compatibility | ||
nav_order: 2 | ||
description: Compatible browsers and operation systems | ||
permalink: /compatibility | ||
--- | ||
|
||
## Compatibility | ||
|
||
### Supported Browsers | ||
|
||
* Google Chrome | ||
* Firefox | ||
|
||
### Supported Operating Systems | ||
|
||
* MacOS | ||
* Linux | ||
* Windows | ||
|
||
## Limitations | ||
|
||
### MacOS | ||
|
||
On macOS, this package requires keychain access to access the Google Chrome encryption key. | ||
You will get a dialogue popup requesting access. | ||
Due to this popup, you cannot use this library completely headlessly to fetch cookies unless you run it once and click `Always Allow`. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
--- | ||
layout: default | ||
title: Fetching Cookies | ||
nav_order: 3 | ||
description: Getting and listing cookies | ||
permalink: /fetching-cookies | ||
--- | ||
|
||
# Get Cookie | ||
|
||
`getCookie` can be used to try and find a cookie based on the domain and cookie name. | ||
If a cookie is not found, the result will be `undefined`. | ||
|
||
```js | ||
import { getCookie, Browser } from 'cookie-thief'; | ||
|
||
const cookie = await getCookie({ | ||
browser: Browser.Chrome, // or Browser.Firefox | ||
domain: '.reddit.com', | ||
cookieName: 'loid', | ||
}); | ||
|
||
/* | ||
{ | ||
name: 'loid', | ||
value: 'the decrypted cookie value here', | ||
domain: '.reddit.com', | ||
path: '/', | ||
} | ||
*/ | ||
``` | ||
|
||
# List Cookies | ||
|
||
`listCookies` can be used to list all cookies for a browser. | ||
If no cookies are found you will get `[]`. | ||
|
||
```js | ||
import { listCookies, Browser } from 'cookie-thief'; | ||
|
||
const cookies = await listCookies({ | ||
browser: Browser.Chrome, // or Browser.Firefox | ||
}) | ||
|
||
/* | ||
[ | ||
{ | ||
name: 'loid', | ||
value: 'the decrypted cookie value here', | ||
domain: '.reddit.com', | ||
path: '/', | ||
} | ||
] | ||
*/ | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
import { Cookie } from './types'; | ||
|
||
export interface CookieProvider { | ||
getCookie(domain: string, cookieName: string): Promise<Cookie | undefined>; | ||
listCookies(): Promise<Cookie[]>; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
export type ChromeCookie = { | ||
host_key: string; | ||
path: string; | ||
name: string; | ||
encrypted_value: Buffer; | ||
}; | ||
|
||
export interface ChromeCookieRepository { | ||
findCookie(cookieName: string, domain: string): ChromeCookie | undefined; | ||
listCookies(): ChromeCookie[]; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
import { CookieProvider } from '../CookieProvider'; | ||
import { Cookie } from '../types'; | ||
import { ChromeCookie, ChromeCookieRepository } from './ChromeCookieRepository'; | ||
import { decrypt } from './decrypt'; | ||
import { getLinuxDerivedKey } from './getDerivedKey'; | ||
|
||
const KEYLENGTH = 16; | ||
const ITERATIONS = 1; | ||
|
||
async function decryptCookie(cookie: ChromeCookie): Promise<string> { | ||
const derivedKey = await getLinuxDerivedKey(KEYLENGTH, ITERATIONS); | ||
return decrypt(derivedKey, cookie.encrypted_value, KEYLENGTH); | ||
} | ||
|
||
async function toCookie(chromeCookie: ChromeCookie): Promise<Cookie> { | ||
return { | ||
value: await decryptCookie(chromeCookie), | ||
host: chromeCookie.host_key, | ||
path: chromeCookie.path, | ||
name: chromeCookie.name, | ||
}; | ||
} | ||
|
||
export class ChromeLinuxCookieProvider implements CookieProvider { | ||
constructor(private db: ChromeCookieRepository) {} | ||
|
||
async getCookie( | ||
domain: string, | ||
cookieName: string, | ||
): Promise<Cookie | undefined> { | ||
const chromeCookie = this.db.findCookie(cookieName, domain); | ||
if (!chromeCookie) return undefined; | ||
return toCookie(chromeCookie); | ||
} | ||
|
||
async listCookies(): Promise<Cookie[]> { | ||
return Promise.all(this.db.listCookies().map(toCookie)); | ||
} | ||
} |
Oops, something went wrong.