Identity Profiles
Anchor allows you to save an existing browser state as “profiles” for use in future browser sessions. This feature enables users to:
- Store authenticated sessions and identities, allowing to stay logged in to websites
- Cache static content to reduce network requests and improve overall speed and performance
The following guide explains how to create and use Identity Profiles in Anchor Browser.
Quick start - Create and use a profile
Authenticate Once
Start a new session in Anchor playground or API, and authenticate to the target service to create a browser context with the required cookies and session data.
Get your session ID
Without closing your current session, go to the sessions page to get your session ID.
Call the 'Create Profile' API
Use the create profile API to save the current browser context as a profile.
Terminate the session
Close the current session to save the profile.
Use the profile in a new session
Now, when using the create session API, pass the profile
parameter with the name of the profile you created to load the saved browser context.
For additional capabilities and advanced use cases, refer to the API documentation for profiles.
Alternative approaches
Method 1 - Mounting a Browser Context
In this method, Anchor Browser uses a pre-authenticated browser context to access protected resources. This approach is recommended because it maintains a secure, isolated environment for authentication without exposing sensitive data.
Authenticate Once
Start by logging into the target service in a dedicated browser session. This creates a browser context with the required cookies and session data.
Export Browser Context
Once authenticated, export the browser context (including cookies and session data) and save it securely.
Mount in Anchor Browser
Use the saved browser context within Anchor Browser to access authenticated services seamlessly.
Method 2 - Playwright-Based Cookie Injection
For cases where browser context mounting isn’t feasible, Playwright allows direct injection of cookies into a browser session, enabling access to authenticated resources.
Obtain Authentication Cookies
Authenticate manually or programmatically to capture the required cookies.
Inject Cookies into Playwright Session
Use Playwright’s API to inject cookies into the browser session before navigating to the authenticated page.
Access Resources
With the cookies injected, the AI agent can interact with the protected service as if logged in.
Code example
Secure Storage of Secrets
To maintain the security of your credentials, API keys, and sensitive data, do not store secrets directly in plaintext within your code. Instead, consider these best practices:
- Environment Variables: Store secrets in environment variables. You can use libraries such as dotenv for Node.js to load variables from a .env file.
- Secrets Management Services: Use secure storage solutions like AWS Secrets Manager, Azure Key Vault, or HashiCorp Vault to manage sensitive data securely.