Skip to content

Commit 50c0b37

Browse files
committed
docs: fix --bot-cookies url required field and Puppeteer context.cookies() usage
1 parent 28827f3 commit 50c0b37

6 files changed

Lines changed: 63 additions & 17 deletions

File tree

CLI_FLAGS.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -202,15 +202,15 @@ Accepts cookie data as either inline JSON or from a file.
202202

203203
**Inline JSON:**
204204
```bash
205-
--bot-cookies='[{"name":"session","value":"abc123","domain":".example.com"}]'
205+
--bot-cookies='[{"url":"https://example.com","name":"session","value":"abc123","domain":".example.com"}]'
206206
```
207207

208208
**From JSON file:**
209209
```bash
210210
--bot-cookies="@/path/to/cookies.json"
211211
```
212212

213-
The file should contain a JSON array of cookie objects with name, value, and domain fields. Guide: [Cookie Management](https://botbrowser.io/docs/identity/cookie-management/)
213+
Each cookie object must include a `url` field. Cookies without `url` are silently skipped. Guide: [Cookie Management](https://botbrowser.io/docs/identity/cookie-management/)
214214

215215
<a id="--bot-bookmarks"></a>
216216
### `--bot-bookmarks`
@@ -512,7 +512,7 @@ chromium-browser \
512512
--bot-profile="/absolute/path/to/profile.enc" \
513513
--bot-config-browser-brand="chrome" \ # ENT Tier2 feature
514514
--bot-config-window="profile" \
515-
--bot-cookies='[{"name":"sessionid","value":"abc123","domain":".example.com"}]' \
515+
--bot-cookies='[{"url":"https://example.com","name":"sessionid","value":"abc123","domain":".example.com"}]' \
516516
--bot-bookmarks='[{"title":"Work Site","url":"https://work.example.com","type":"url"}]' \
517517
--user-data-dir="/tmp/instance1" &
518518

botbrowser-control/src/renderer/js/app.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1381,7 +1381,7 @@
13811381
<div class="form-section-title">${I.cookie} Cookies & Bookmarks</div>
13821382
<div class="form-group full">
13831383
<label class="form-label">Cookies ${badge('PRO')}</label>
1384-
<textarea class="form-textarea" id="f-cookies" rows="4" placeholder='[{"name":"session","value":"abc","domain":".example.com"}] or @/path/to/cookies.json'>${esc(d.cookies||'')}</textarea>
1384+
<textarea class="form-textarea" id="f-cookies" rows="4" placeholder='[{"url":"https://example.com","name":"session","value":"abc","domain":".example.com"}] or @/path/to/cookies.json'>${esc(d.cookies||'')}</textarea>
13851385
</div>
13861386
<div class="form-group full">
13871387
<label class="form-label">Bookmarks</label>

docs/guides/getting-started/CLI_RECIPES.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -297,7 +297,7 @@ chromium-browser \
297297
```bash
298298
chromium-browser \
299299
--bot-profile="/path/to/profile.enc" \
300-
--bot-cookies='[{"name":"session","value":"abc123","domain":".example.com"}]' \
300+
--bot-cookies='[{"url":"https://example.com","name":"session","value":"abc123","domain":".example.com"}]' \
301301
--user-data-dir="$(mktemp -d)"
302302
```
303303

docs/guides/getting-started/PROFILE_MANAGEMENT.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -204,7 +204,7 @@ Use one profile with different session settings to create distinct user sessions
204204
chromium-browser \
205205
--bot-profile="/path/to/profile.enc" \
206206
--proxy-server=socks5://user:pass@us-proxy.example.com:1080 \
207-
--bot-cookies='[{"name":"session","value":"us-user","domain":".example.com"}]' \
207+
--bot-cookies='[{"url":"https://example.com","name":"session","value":"us-user","domain":".example.com"}]' \
208208
--user-data-dir="$(mktemp -d)" &
209209

210210
# Session 2: German user
@@ -213,7 +213,7 @@ chromium-browser \
213213
--proxy-server=socks5://user:pass@de-proxy.example.com:1080 \
214214
--bot-config-timezone=Europe/Berlin \
215215
--bot-config-locale=de-DE \
216-
--bot-cookies='[{"name":"session","value":"de-user","domain":".example.com"}]' \
216+
--bot-cookies='[{"url":"https://example.com","name":"session","value":"de-user","domain":".example.com"}]' \
217217
--user-data-dir="$(mktemp -d)" &
218218
```
219219

docs/guides/identity/COOKIE_MANAGEMENT.md

Lines changed: 55 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ You can provide cookies as inline JSON directly in the flag value, or load them
3333
```bash
3434
chromium-browser \
3535
--bot-profile="/path/to/profile.enc" \
36-
--bot-cookies='[{"name":"session_id","value":"abc123","domain":".example.com"}]'
36+
--bot-cookies='[{"url":"https://example.com","name":"session_id","value":"abc123","domain":".example.com"}]'
3737
```
3838

3939
### From a file
@@ -56,36 +56,38 @@ The file should contain a JSON array of cookie objects.
5656

5757
2. **Cookie injection.** Cookies are injected into the browser's cookie store before any page navigation occurs. This means the first HTTP request already includes the injected cookies.
5858

59-
3. **Domain matching.** Each cookie must include a `domain` field. The browser only sends cookies to matching domains, following standard cookie rules.
59+
3. **Domain matching.** Each cookie must include a `url` field. The browser uses it to set the cookie origin and only sends cookies to matching domains, following standard cookie rules.
6060

6161
### Cookie Format
6262

6363
Each cookie object supports these fields:
6464

6565
| Field | Required | Description |
6666
|-------|----------|-------------|
67+
| `url` | Yes | Full URL used to set the cookie (e.g., `https://example.com`). Required for the cookie to be accepted. |
6768
| `name` | Yes | Cookie name. |
6869
| `value` | Yes | Cookie value. |
69-
| `domain` | Yes | Domain the cookie belongs to. Prefix with `.` for subdomains (e.g., `.example.com`). |
70+
| `domain` | No | Domain the cookie belongs to. Prefix with `.` for subdomains (e.g., `.example.com`). |
7071
| `path` | No | Cookie path. Defaults to `/`. |
71-
| `secure` | No | Whether the cookie requires HTTPS. Defaults to `false`. |
72+
| `secure` | No | Whether the cookie requires HTTPS. Defaults to `true`. |
7273
| `httpOnly` | No | Whether the cookie is HTTP-only (not accessible via JavaScript). Defaults to `false`. |
73-
| `sameSite` | No | SameSite attribute: `Strict`, `Lax`, or `None`. |
74-
| `expires` | No | Expiration time as a Unix timestamp (seconds since epoch). |
74+
| `sameSite` | No | SameSite attribute: `strict`, `lax`, or `none`. |
75+
| `expirationDate` | No | Expiration time as a Unix timestamp (seconds since epoch). |
7576

7677
---
7778

7879
<a id="common-scenarios"></a>
7980

8081
## Common Scenarios
8182

82-
### Pre-authenticated session
83+
### Pre-authenticated session (Playwright)
8384

8485
```javascript
8586
import { chromium } from "playwright-core";
8687

8788
const cookies = JSON.stringify([
8889
{
90+
url: "https://example.com",
8991
name: "session_id",
9092
value: "abc123def456",
9193
domain: ".example.com",
@@ -94,6 +96,7 @@ const cookies = JSON.stringify([
9496
httpOnly: true,
9597
},
9698
{
99+
url: "https://example.com",
97100
name: "user_prefs",
98101
value: "theme=dark",
99102
domain: ".example.com",
@@ -115,16 +118,55 @@ await page.goto("https://example.com/dashboard"); // Loads as authenticated user
115118
await browser.close();
116119
```
117120

121+
### Pre-authenticated session (Puppeteer)
122+
123+
With Puppeteer, use `browser.defaultBrowserContext()` to access the context that `--bot-cookies` injects into. `context.cookies()` returns all cookies for the context without a URL argument.
124+
125+
```javascript
126+
import puppeteer from "puppeteer-core";
127+
128+
const cookies = JSON.stringify([
129+
{
130+
url: "https://example.com",
131+
name: "session_id",
132+
value: "abc123def456",
133+
domain: ".example.com",
134+
path: "/",
135+
secure: true,
136+
httpOnly: true,
137+
},
138+
]);
139+
140+
const browser = await puppeteer.launch({
141+
executablePath: process.env.BOTBROWSER_EXEC_PATH,
142+
headless: true,
143+
args: [
144+
"--bot-profile=/path/to/profile.enc",
145+
`--bot-cookies=${cookies}`,
146+
],
147+
});
148+
149+
const context = browser.defaultBrowserContext();
150+
const page = await context.newPage();
151+
await page.goto("https://example.com/dashboard");
152+
153+
const injectedCookies = await context.cookies();
154+
console.log(injectedCookies);
155+
156+
await browser.close();
157+
```
158+
118159
### Cookie consent pre-set
119160

120161
```javascript
121162
const consentCookies = JSON.stringify([
122163
{
164+
url: "https://example.com",
123165
name: "cookie_consent",
124166
value: "accepted",
125167
domain: ".example.com",
126168
path: "/",
127-
expires: Math.floor(Date.now() / 1000) + 365 * 24 * 60 * 60,
169+
expirationDate: Math.floor(Date.now() / 1000) + 365 * 24 * 60 * 60,
128170
},
129171
]);
130172

@@ -145,6 +187,7 @@ Create a `cookies.json` file:
145187
```json
146188
[
147189
{
190+
"url": "https://example.com",
148191
"name": "session_id",
149192
"value": "abc123",
150193
"domain": ".example.com",
@@ -153,6 +196,7 @@ Create a `cookies.json` file:
153196
"httpOnly": true
154197
},
155198
{
199+
"url": "https://example.com",
156200
"name": "locale",
157201
"value": "en-US",
158202
"domain": ".example.com",
@@ -175,7 +219,7 @@ When building the `--bot-cookies` flag in JavaScript, do not wrap the JSON value
175219

176220
```javascript
177221
// Correct
178-
const cookies = [{ name: "sid", value: "abc", domain: ".example.com" }];
222+
const cookies = [{ url: "https://example.com", name: "sid", value: "abc", domain: ".example.com" }];
179223
args.push("--bot-cookies=" + JSON.stringify(cookies));
180224

181225
// Wrong - extra quotes become part of the value
@@ -190,6 +234,8 @@ args.push(`--bot-cookies='${JSON.stringify(cookies)}'`);
190234

191235
| Problem | Solution |
192236
|---------|----------|
237+
| Cookies not injected (silently skipped) | Each cookie object must include a `url` field (e.g., `"url": "https://example.com"`). Without it, the cookie is silently dropped. |
238+
| Puppeteer: `context.cookies()` returns empty | Use `browser.defaultBrowserContext()`. Cookies from `--bot-cookies` are injected into the default context only, not into contexts created with `browser.createBrowserContext()`. |
193239
| Cookies not sent with requests | Verify the `domain` field matches the target site. Use `.example.com` (with leading dot) to include subdomains. |
194240
| "Invalid JSON" error | Check that the cookie value is a valid JSON array. Use a JSON validator if needed. |
195241
| File not found | When using `@/path/to/file.json`, ensure the path is absolute. |

docs/guides/identity/HISTORY_SEEDING.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,7 @@ const browser = await chromium.launch({
111111
"--proxy-server=socks5://user:pass@proxy.example.com:1080",
112112
"--bot-inject-random-history",
113113
`--bot-cookies=${JSON.stringify([
114-
{ name: "consent", value: "accepted", domain: ".example.com" },
114+
{ url: "https://example.com", name: "consent", value: "accepted", domain: ".example.com" },
115115
])}`,
116116
`--bot-bookmarks=${JSON.stringify([
117117
{ title: "Google", type: "url", url: "https://www.google.com" },

0 commit comments

Comments
 (0)