Hyperbrowser profiles allow you to reuse browser state like cookies, local storage, and network cache across multiple sessions. This can improve performance and enable seamless workflows requiring persistent data.
How Profiles Work
A profile is essentially a saved snapshot of a browser's user data directory. By default, each Hyperbrowser session uses a fresh user data directory to ensure isolation.
When you create a profile and then use and persist it in a new session, Hyperbrowser saves that session's user data directory. You can then attach the profile to future sessions to pick up where you left off.
Common use cases for profiles include:
Reusing authenticated sessions
Improving page load times with a primed cache
Preserving application state across sessions
Using Profiles
1. Create a Profile
First, create a new profile using the Profiles API. Note the returned id - you'll need this to attach the profile to sessions.
When creating a new session with the Sessions API, include the id in the profile field:
const session = await client.sessions.create({
profile: {
id: "<PROFILE_ID>",
persistChanges: true, // set to true for the first session of a new profile
},
});
session = client.sessions.create(
params=CreateSessionParams(
profile=CreateSessionProfile(
id="<PROFILE_ID>",
# set to true for the first session of a new profile
persist_changes=True,
),
)
)
Set "persistChanges": true in the profile object if you want the session to update the profile with any changes to cookies, cache, etc. You will need to do this for the first time you use a new profile in a session so it can be used in subsequent sessions.
Once whatever changes to the profile have been made, the session should be safely closed to ensure that the profile is saved. After that unless the "persistChanges": trueoption is passed to the session again, the session will be immutable.
3. Reuse Profile
Attach the same id to additional sessions to reuse browser state. Created profiles are reusable until you delete them.