Overview

Cookies provide a flexible way to authenticate your sessions in Notte. While we recommend using the secure vault for credential management, cookies offer an alternative approach that might be more convenient for certain use cases.

Uploading Cookies to Your Session

Here’s how to upload cookies to your Notte session:

upload_cookies.py
from pathlib import Path
from notte_sdk import NotteClient

notte = NotteClient()

# Upload cookies from a JSON file
cookie_path = Path("path/to/cookies.json")
# create a new session
with notte.Session() as session:
	_ = session.upload_cookies(cookie_file=str(cookie_path))

	# Use the cookies in your session
	_ = notte.agents.run(
		task="go to nottelabs/notte and star the repo if it's not already starred",
		url="https://github.com/nottelabs/notte",
		session_id=session.session_id
	)

Important Notes

  • The cookies file must be a valid JSON file
  • Cookies are available for all sessions started after upload
  • You need to manage cookie expiration manually
  • Upload new cookies when they expire

Extracting Cookies from Your Browser

Here’s a step-by-step guide to extract cookies from your browser:

extract_cookies.py
import json
from pathlib import Path
from patchright.sync_api import sync_playwright

cookie_path = Path("github_cookies.json")
# Initialize Playwright
with sync_playwright() as playwright:
	browser = playwright.chromium.launch(headless=False)
	context = browser.new_context()
	page = context.new_page()

	# Navigate to login page
	github_login_url = "https://github.com/login"
	page.goto(github_login_url)

	print("Please log into GitHub in the browser window...")
	input("Press Enter after you've logged in...")

	# Save cookies to file
	print("Login successful. Saving cookies...")
	cookies = context.cookies(urls=["https://github.com"])

	if cookies:
		cookie_path.write_text(json.dumps(cookies, indent=4))
		print(f"Cookies saved to {cookie_path}")
	else:
	    print("No cookies found to save.")

Best Practices

  1. Security

    • Store cookie files securely
    • Don’t commit cookie files to version control
    • Regularly rotate cookies for sensitive services
  2. Maintenance

    • Monitor cookie expiration dates
    • Set up reminders to refresh cookies
    • Keep backup copies of valid cookies
  3. Troubleshooting

    • If a session fails, try uploading fresh cookies
    • Check if cookies are still valid
    • Verify the cookie file format is correct