Auth states in Scrapybara allow you to capture, save, and reuse website authentication data across browser sessions. This feature is extremely useful for:
Auth states capture cookies, local storage, session storage, and other browser-based authentication data.
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).
Once you’ve logged in, you can save the auth state with a name:
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.
Once you’ve logged in, you can modify the auth state with a new name:
Once you’ve saved an auth state, you can use it to authenticate future browser sessions without going through the login process again:
The Scrapybara Playground provides a visual interface for managing auth states:
Create an auth state:
Use an existing auth state:
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).