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.
Manage Profiles in the console
The console calls persistent browser Contexts Profiles. Profile IDs and SDK/API context fields still refer to the same resource.
- Create a Profile and choose Save and set up authentication, or choose Set up authentication on an existing Profile.
- The console creates and opens a Chromium session with that Profile in read-write mode. Log in to the websites you need in the embedded browser.
- Choose Save and close. The console uses the same normal session shutdown as Sessions, then waits for the browser to close and the Profile to become available.
Closing the dialog leaves the session running. Open Set up authentication again in the same console tab to resume it; the session is also visible in Sessions. If startup or saving fails, retry with the existing session. A Profile created before a browser startup failure remains in the list.
You can still select a Profile when creating a Chromium session in Sessions. Check its lock state and associated sessions before reusing or deleting it. Availability and limits depend on the project plan. The console does not detect which websites are logged in or offer a way to discard login changes.
