Skip to content

Commit ebd8690

Browse files
Merge pull request #19 from Crowdhandler/maintenance/documentation-catchup
Document cookieMaxAgeSeconds, forceCloudflareWorkers in README
2 parents 3c9d61c + 610a5b2 commit ebd8690

1 file changed

Lines changed: 39 additions & 0 deletions

File tree

README.md

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -340,6 +340,11 @@ const instance = crowdhandler.init({
340340
trustOnFail: true, // Allow access if API fails
341341
fallbackSlug: '', // Fallback room slug when trustOnFail is false
342342
cookieName: 'crowdhandler', // Custom cookie name (default: 'crowdhandler')
343+
cookieMaxAgeSeconds: 86400, // Optional. Persist the cookie via Max-Age (seconds).
344+
// Omit for a session cookie (default).
345+
forceCloudflareWorkers: true, // Optional. Bypass navigator-based runtime inference
346+
// and treat the runtime as Cloudflare Workers. Only `true`
347+
// is accepted; omit for auto-detection.
343348
waitingRoom: false, // Set to true if SDK is running in a waiting room context
344349
liteValidator: false, // Enable lite validator mode (default: false)
345350
roomsConfig: [{ // Array of room configurations for lite validator
@@ -400,6 +405,40 @@ This is useful when:
400405
- Avoiding conflicts with existing cookies
401406
- Meeting specific naming conventions
402407
408+
## Cookie Persistence
409+
410+
By default the CrowdHandler cookie is a **session cookie** — the browser drops it when the user fully quits (note: many browsers restore session cookies if "continue where you left off" is enabled). For waiting-room use cases where you want a queued user's position to survive a browser restart, opt in to persistence with `cookieMaxAgeSeconds`:
411+
412+
```javascript
413+
const { gatekeeper } = crowdhandler.init({
414+
publicKey: 'YOUR_PUBLIC_KEY',
415+
options: {
416+
cookieMaxAgeSeconds: 86400 // Persist for 24 hours via Max-Age
417+
}
418+
});
419+
```
420+
421+
Notes:
422+
- The value is written as the cookie's `Max-Age` attribute (preferred over `Expires` because it isn't affected by client clock skew).
423+
- The option applies to every Set-Cookie the SDK emits — both while the user is queued and after promotion.
424+
- Omit the option (or leave it `undefined`) to keep the original session-cookie behaviour.
425+
426+
## Forcing the Cloudflare Workers Runtime
427+
428+
The SDK infers a Cloudflare Workers runtime from `navigator.userAgent`. If that signal is unreliable in your environment (custom workerd builds, bundlers that strip globals, test harnesses) you can make the decision explicit:
429+
430+
```javascript
431+
const { gatekeeper } = crowdhandler.init({
432+
publicKey: env.CROWDHANDLER_PUBLIC_KEY,
433+
cloudflareWorkersRequest: request,
434+
options: {
435+
forceCloudflareWorkers: true
436+
}
437+
});
438+
```
439+
440+
Only `true` is accepted — omit the option to fall back to auto-detection. With `debug: true`, the SDK logs which signal drove the decision, e.g. `[CH] Cloudflare Workers runtime: true (via override)` vs `(via navigator inference)`. The override is reset on every `init()` call so it never leaks across re-initialisations.
441+
403442
## API Client
404443
405444
The SDK provides a unified client for both public and private APIs:

0 commit comments

Comments
 (0)