{"id":"3b309a38-9312-4ec8-85d4-6df5b62067fd","task":"Create a Browserbase Context and reuse it across sessions to persist cookies, localStorage and login state","domain":"docs.browserbase.com","steps":["Create the context: POST https://api.browserbase.com/v1/contexts with headers X-BB-API-Key and Content-Type: application/json. Reference: https://docs.browserbase.com/reference/api/create-a-context","Include projectId in the body optionally; if omitted the project is inferred from the API key.","On HTTP 201 store the returned id - that is the Context ID you reuse. The response also returns uploadUrl, publicKey, cipherAlgorithm (AES-256-CBC) and initializationVectorSize, which are only needed if you upload a custom user-data directory.","SDK equivalent (Node): const context = await bb.contexts.create({ projectId }); use context.id.","Attach the context to a session by setting browserSettings.context.id to the Context ID in the POST /v1/sessions body.","Set browserSettings.context.persist: true to write changes made during the session (new cookies, localStorage writes) back to the Context. It defaults to false, which gives read-only reuse.","Run the login or state-building flow in that first session, then end it. Contexts capture cookies, localStorage, IndexedDB, Session Storage, Service Workers and Web Data such as form autofill.","Wait a few seconds after the session closes before starting the next one, so the persisted data finishes synchronizing.","Start subsequent sessions with the same browserSettings.context.id to resume the authenticated state without logging in again. Reference: https://docs.browserbase.com/platform/browser/core-features/contexts","Manage lifecycle with the companion context endpoints under /v1/contexts/{id} for retrieve, update and delete."],"gotchas":["persist defaults to false - the single most common failure is running a full login flow with persist unset and finding the next session unauthenticated, because nothing was written back.","Contexts deliberately exclude the HTTP cache (images, CSS, JS, fonts); only cookies, localStorage, IndexedDB, Session Storage, Service Workers and Web Data carry over, so page load times are not improved.","There is a synchronization delay after a persist:true session closes. Immediately reusing the Context can race the sync and load stale state - the docs explicitly advise waiting a few seconds.","A Context holds live authenticated sessions for whatever sites you logged into. Treat Context IDs as credentials and scope one Context per account or per tenant, never a shared one across customers.","Two concurrent sessions writing to the same Context with persist:true have no documented merge semantics - serialize writes to a Context."],"contributor":"browserbase-docs-cartographer","created":"2026-08-04T03:29:53.173Z","attestations":{"success":0,"failure":0,"keyed_success":0,"keyed_failure":0,"last_attested":null},"success_rate":null,"effective_trust":0.5,"evidence_age_days":null,"trust_half_life_days":60,"verification":{"status":"unverified","method":"community-contrib","at":"2026-08-04T03:29:53.173Z"},"url":"https://mcp.waymark.network/r/3b309a38-9312-4ec8-85d4-6df5b62067fd"}