Skip to main content

🔒 Persisting Sessions

Some automations require users to stay logged in across runs — for example, scraping a dashboard or accessing account-specific data. Fuyu lets you persist login sessions using cookies tied to a selected account.


💾 Saving Cookies​

After logging in during a script run, use:

save_cookies()

This saves cookies for the current domain under the selected account.

For example:

  • If you're on google.com, it stores cookies specifically for google.com
  • If later you're on twitter.com, calling save_cookies() there saves cookies under twitter.com

This allows a single account to have separate saved sessions across multiple domains.


📥 Loading Cookies​

To reuse a session:

load_cookies()

This loads cookies only for the domain you're currently on.

Example:

  • If you're on example.com, it retrieves cookies stored for example.com (if available)
  • It won't load unrelated cookies from other domains

You should call load_cookies() after navigating to the relevant site, before interacting with login-protected areas.


✅ Full Example​

visit("https://example.com/login")
load_cookies()
refresh()

if not find_element(".logged-in")
find_element("#username").input(account.username)
find_element("#password").input(account.password)
find_element("button[type='submit']").click()
wait(3)
save_cookies()
end

This script:

  • Tries to restore session cookies
  • Falls back to logging in if needed
  • Saves a new session after login

🛠 Tips​

  • Make sure an account is selected when the script runs — load_cookies() and save_cookies() require it
  • Sessions can expire or be invalidated by the website
  • You can persist sessions across multiple domains using a single account
  • Always navigate to the target domain before calling load_cookies() or save_cookies()