Reuse a persistent Context
Reuse a persistent Context.
A Context stores browser profile state across Chromium sessions. A browser session is one running instance; its lifetime is shorter than the Context's. Use a dedicated Context for each account or isolated workflow.
Safe reuse sequence
- Create a Context or select an existing one with the Node.js or Python SDK.
- Start a Chromium session with the Context ID and explicit access mode.
- Complete login or browser work. Never publish cookies or downloaded profiles.
- Close the session and wait for shutdown and Context availability.
- Start a second session using the same Context and verify the expected login state on the target site.
Example create options (inside your existing SDK lifecycle):
const session = await client.sessions.create({
browserMode: 'normal',
context: { id: process.env.LEXMOUNT_CONTEXT_ID!, mode: 'readWrite' },
});Set LEXMOUNT_CONTEXT_ID to an authorized Context in the same service/project. The snippet only creates a session; always apply the cleanup from session lifecycle.
Locks and persistence
Treat lock conflicts as a signal to inspect the owning session. Do not force-release a live writer just to make a retry succeed. Reusing a Context is not a guarantee that the target website's login remains valid: cookies can expire and the site may require reauthentication. Read-only access is not a way to persist new login changes.
Use the maintained context-basic, context-modes, and context-lock-handling scripts in the Node examples. Context features described here target Chromium; do not apply them to Moli without an explicit supported contract.
