Load Cookies
Loads and decrypts browser cookies from an encrypted file using AES decryption. This node allows you to restore previously saved browser sessions for web automation workflows.
Common Properties
- Name - The custom name of the node.
- Color - The custom color of the node.
- Delay Before (sec) - Waits in seconds before executing the node.
- Delay After (sec) - Waits in seconds after executing node.
- Continue On Error - Automation will continue regardless of any error. The default value is false.
If the ContinueOnError property is true, no error is caught when the project is executed, even if a Catch node is used.
Inputs
- Load Path - Path to the encrypted cookie file to load. Must point to a valid encrypted cookie file created by the Save Cookies node. Example:
C:\cookies\session.dator/home/user/cookies/session.dat
Options
- AES Key - AES encryption key in hexadecimal format for decryption. Must be the same key used to encrypt the cookies. Must be a valid 16, 24, or 32-byte hex string (32, 48, or 64 hex characters). Store this key securely in a Vault credential.
Output
- Cookies - Decrypted cookies loaded from the file. The cookies are stored in
msg.cookiesand can be used with the Set Cookies node to restore a browser session.
How It Works
The Load Cookies node performs the following operations:
- Validates the load path
- Reads the encrypted cookie file from disk
- Retrieves the AES decryption key from credentials
- Decrypts the file data using AES-CBC
- Parses the decrypted JSON data into cookie objects
- Stores the cookies in the message scope for use by other nodes
Cookie Structure
The loaded cookies contain the following properties:
- name - Cookie name
- value - Cookie value
- domain - Domain for which the cookie is valid
- path - Path within the domain
- expires - Expiration timestamp
- maxAge - Maximum age in seconds
- secure - Boolean indicating if cookie is secure (HTTPS only)
- httpOnly - Boolean indicating if cookie is HTTP only
- sameSite - SameSite attribute (0=None, 1=Lax, 2=Strict)
Examples
Example 1: Restore Login Session
// Load previously saved session cookies and restore browser session
// This allows skipping the login process
// 1. Load Cookies from file
// Load Path: C:\sessions\linkedin-session.dat
// AES Key: {{vault.session_encryption_key}}
// 2. Open Browser
// URL: https://www.linkedin.com
// 3. Set Cookies (from Browser package)
// Page ID: {{msg.pageId}}
// Cookies: {{msg.cookies}}
// Now the browser has the authenticated session restored
Example 2: Load Session with Error Handling
// Attempt to load saved session, fall back to login if it fails
// Try block:
// 1. Load Cookies
// Load Path: /home/user/sessions/gmail-session.dat
// AES Key: {{vault.gmail_key}}
//
// 2. Open Browser and Set Cookies
// (session restored successfully)
// Catch block:
// 1. Open Browser
// 2. Navigate to login page
// 3. Perform login
// 4. Save Cookies for next time
Example 3: Load Different Sessions Dynamically
// Load different user sessions based on configuration
// Custom scope variable: sessionName = "user1"
// Load Cookies:
// Load Path: C:\sessions\{{sessionName}}-cookies.dat
// AES Key: {{vault.multi_account_key}}
// This allows managing multiple account sessions
Example 4: Session Validation Workflow
// Load session, test if valid, re-authenticate if needed
// 1. Load Cookies
// Load Path: {{config.sessionPath}}
// AES Key: {{vault.session_key}}
// 2. Open Browser and Set Cookies
// 3. Navigate to a protected page
// 4. Check if redirected to login (session invalid)
// If invalid:
// - Perform login
// - Save Cookies to update the session file
// If valid:
// - Continue with automation
Best Practices
Session Management
- Validate Sessions: After loading cookies, verify they're still valid by checking a protected page
- Graceful Degradation: Use Try-Catch to fall back to login if cookie loading fails
- Update Regularly: Periodically save fresh cookies to update tokens and extend session life
- Session Naming: Use descriptive names for session files to manage multiple accounts
Security
- Same Key Required: The AES key used to load must match the key used to save
- Secure Key Storage: Always use Vault credentials for AES keys
- Key Rotation: When rotating encryption keys, re-save all cookie files with the new key
- Access Control: Restrict file system permissions on encrypted cookie files
File Management
- Path Validation: Verify files exist before attempting to load
- Absolute Paths: Use absolute paths to avoid confusion with working directories
- Organized Storage: Maintain a consistent directory structure for cookie files
- Cleanup: Delete expired or unused cookie files regularly
Performance
- Cache Strategy: Load cookies once at the start of your workflow, not repeatedly
- Minimal Reloads: Only reload cookies when sessions expire or need refreshing
- Fast Startup: Loading encrypted cookies is much faster than re-authenticating
Error Handling
The node will return specific errors in the following cases:
- ErrInvalidArg: "Path cannot be empty" - No load path provided
- ErrRuntime: "Failed to read cookie file" - File doesn't exist, insufficient permissions, or I/O error
- ErrCredentials: "Failed to get AES key" - AES key credential not found or inaccessible
- ErrCredentials: "AES key not found in credentials" - Credential doesn't contain the key value
- ErrInvalidArg: "Invalid hex key format" - AES key is not valid hexadecimal
- ErrRuntime: "Failed to decrypt cookies" - Decryption failed (usually due to wrong key or corrupted file)
- ErrRuntime: "Failed to parse cookies" - Decrypted data is not valid JSON (corrupted file or wrong key)
Common Issues and Solutions
Issue: "Failed to decrypt cookies"
Cause: Wrong AES key or corrupted file
Solution:
- Verify you're using the exact same key that was used to save the cookies
- Check that the file hasn't been modified or corrupted
- Try re-saving the cookies with Save Cookies node
- Ensure the key is in the correct hexadecimal format
Issue: "Failed to read cookie file"
Cause: File doesn't exist or insufficient permissions
Solution:
- Verify the file path is correct and the file exists
- Check read permissions for the file
- Use absolute paths to avoid path resolution issues
- Ensure the file wasn't moved or deleted
Issue: "Failed to parse cookies"
Cause: File was encrypted with a different key or is corrupted
Solution:
- Confirm the AES key matches the one used for encryption
- Check if the file is a valid cookie file (not a different encrypted file)
- Try saving new cookies if the original is corrupted
Issue: Cookies Load but Session Doesn't Work
Cause: Cookies have expired or are not valid for the current domain
Solution:
- Check cookie expiration timestamps
- Ensure you're navigating to the same domain the cookies were saved from
- Save fresh cookies and try again
- Some websites invalidate sessions after a period of inactivity
Issue: "Invalid hex key format"
Cause: AES key contains non-hexadecimal characters or wrong length
Solution:
- Ensure the key only contains 0-9 and a-f characters
- Verify the key length is 32, 48, or 64 characters
- Check for extra spaces or newlines in the vault credential
Usage Notes
- The encrypted cookie file must have been created by the Save Cookies node
- Cookies can only be decrypted with the exact same AES key used for encryption
- Loaded cookies are automatically placed in
msg.cookiesfor easy use with Set Cookies - The node supports cookie files created on any platform (Windows, Linux, macOS)
- Cookie expiration is based on the original expiration time when they were saved
- If cookies have expired, they may not work even if successfully loaded
- The decryption process validates the integrity of the data using PKCS7 padding
- Large cookie files (1000+ cookies) may take slightly longer to decrypt but are fully supported
Workflow Integration
Typical Authentication Flow
- Load Cookies - Attempt to load saved session
- Open Browser - Launch browser instance
- Set Cookies - Apply loaded cookies to browser
- Navigate - Go to target page
- Verify - Check if authentication is valid
- Fallback - If invalid, perform login and save new cookies
Session Refresh Pattern
- Load Cookies - Load existing session
- Open Browser & Set Cookies - Restore session
- Perform Automation - Execute tasks
- Save Cookies - Update stored session with refreshed tokens
Multi-Account Management
- Loop through accounts - Iterate account list
- Load Cookies - Load account-specific cookie file
- Open Browser & Set Cookies - Restore that account's session
- Perform Tasks - Execute account-specific automation
- Close Browser - Clean up before next iteration
Related Nodes
- Save Cookies - Encrypt and save cookies to a secure file
- Set Cookies - Apply cookies to a browser session
- Get Cookies - Retrieve cookies from a browser session
- Open Browser - Open a browser for web automation