Auth States
Save and load browser auth states
What are auth states?
Auth states in Scrapybara allow you to capture, save, and reuse website authentication data across browser sessions. This feature is extremely useful for:
- Automating login flows
- Persisting authentication between browser instances
- Avoiding repetitive login procedures in your automation scripts
- Testing authenticated features without manual intervention
Auth states capture cookies, local storage, session storage, and other browser-based authentication data.
Save auth state
When you’ve successfully authenticated with a website in the browser, you can save the authentication state for future use. Each auth state is identified by a unique ID and an optional name (defaults to “default” if not specified).
Python
TypeScript
Once you’ve logged in, you can save the auth state with a name:
Modify auth state
If you have an existing auth state that you want to update with new authentication data, you can use the modify_auth
functionality. This is useful when credentials have changed or when an existing auth state needs to be refreshed.
Python
TypeScript
Once you’ve logged in, you can modify the auth state with a new name:
Load auth state
Once you’ve saved an auth state, you can use it to authenticate future browser sessions without going through the login process again:
Python
TypeScript
Using auth states in the playground
The Scrapybara Playground provides a visual interface for managing auth states:
-
Create an auth state:
- Head to the Scrapybara auth page
- Click on the “Create auth state” button
- Log in to the website and save the auth state
-
Use an existing auth state:
- Click the fingerprint icon next to the instance dropdown menu
- Choose your saved auth state from the dropdown
- When you start the instance, it will automatically apply the authentication data
Best practices
Here are some best practices for working with auth states:
-
Use descriptive names: Name your auth states clearly (e.g., “github_login” or “shopify_admin”) for easy identification.
-
Refresh regularly: Authentication tokens can expire. Consider updating your auth states periodically using the
modify_auth
functionality. -
Test before use: Always verify that your auth state is still valid before relying on it for critical automation.
-
Multiple auth states: Maintain separate auth states for different environments (e.g., production, staging, development).