VLearnVibium

How to Get and Set Cookies in Vibium

Get and set cookies in Vibium with cookies() and set_cookies(). Runnable Python examples for reading, adding, and clearing cookies to reuse sessions.

By Pramod Dutta··3 min read·Verified with Vibium 26.2
▶ Animated overview · made with Remotion

To get and set cookies in Vibium, call vibe.cookies() to read the current cookies and vibe.set_cookies([...]) to write them. Cookies live at the context level — each browser context has its own isolated cookie jar — and Vibium reads and writes them through the WebDriver BiDi storage.getCookies and storage.setCookie commands, so you work with the live browser state rather than parsing document.cookie. cookies() returns a list of dictionaries, each with fields like name, value, domain, path, secure, and httpOnly. set_cookies() takes a list of those dictionaries and installs them, which lets you pre-seed an authentication cookie and skip the login screen entirely. clear_cookies() wipes the jar to start from a clean, logged-out state. This makes cookies the fastest way to reuse a session across runs or to set up test fixtures.

How do I read the current cookies?

Call vibe.cookies() after navigating, and Vibium returns a list of cookie dictionaries reflecting the live browser state. Each entry includes the standard cookie attributes.

from vibium import browser_sync as browser
 
vibe = browser.launch()
vibe.go("https://example.com")
 
cookies = vibe.cookies()
for c in cookies:
    print(c["name"], "=", c["value"])
 
# Each cookie is a dict: name, value, domain, path, secure, httpOnly, ...
print(cookies[0])
 
vibe.quit()

Because Vibium reads cookies through BiDi's storage.getCookies rather than document.cookie, you also see httpOnly cookies that JavaScript can't access — exactly the ones that usually carry the session token. That makes cookies() reliable for inspecting auth state during a test.

Pass a list of cookie dictionaries to vibe.set_cookies(). Each cookie needs at least name, value, and domain; add path, secure, or httpOnly as needed.

from vibium import browser_sync as browser
 
vibe = browser.launch()
vibe.go("https://example.com")  # establish the domain first
 
# Pre-seed a session cookie, then reload to apply it.
vibe.set_cookies([
    {
        "name": "session",
        "value": "abc123token",
        "domain": "example.com",
        "path": "/",
    }
])
 
vibe.reload()
# The page now loads as if you were already logged in.
 
vibe.quit()

Pre-seeding a cookie is the classic way to bypass a slow login flow: grab a valid session value once, then inject it on every run so your script lands straight on the authenticated page. Navigate to the domain first so the cookie's domain matches, then reload() (or go() again) so the request carries the cookie.

How do I clear cookies for a clean start?

Call vibe.clear_cookies() to delete the cookies in the current context, resetting session and tracking state. This is ideal for guaranteeing a test starts logged out.

from vibium import browser_sync as browser
 
vibe = browser.launch()
vibe.go("https://example.com")
 
vibe.clear_cookies()
vibe.reload()
# The page now behaves as a brand-new, logged-out visitor.
 
vibe.quit()

Clearing cookies is a quick reset, but for strong test isolation prefer a separate browser context: each context Vibium creates has its own cookie jar and storage, so parallel tests never leak state into one another. Reach for clear_cookies() for a quick within-context reset and contexts for true isolation.

How do I reuse a saved session across runs?

Read the cookies at the end of one run, save them to disk, and load them back at the start of the next — turning a one-time login into a reusable fixture.

import json
from vibium import browser_sync as browser
 
# Run 1: log in, then save cookies.
vibe = browser.launch()
vibe.go("https://example.com")
# ... perform login here ...
with open("session.json", "w") as f:
    json.dump(vibe.cookies(), f)
vibe.quit()
 
# Run 2: restore cookies and skip the login UI.
vibe = browser.launch()
vibe.go("https://example.com")
with open("session.json") as f:
    vibe.set_cookies(json.load(f))
vibe.reload()
vibe.quit()

This pattern pairs perfectly with the automate a login flow guide: log in once with the UI, persist the cookies, and every later run restores the session in a single set_cookies() call.

Next steps

Frequently asked questions

How do I read cookies in Vibium?

Call cookies() to get a list of the current cookies, each as a dictionary with fields like name, value, domain, and path. Vibium reads them through the WebDriver BiDi storage.getCookies command, so you get the live browser state without parsing document.cookie yourself.

How do I set a cookie in Vibium?

Call set_cookies() with a list of cookie dictionaries, each including at least name, value, and domain. Vibium writes them via the BiDi storage.setCookie command, so you can pre-seed an auth cookie before navigating and skip the login UI entirely.

How do I clear cookies in Vibium?

Call clear_cookies() to delete the cookies in the current context. This resets session and tracking state, which is useful for starting a test from a clean, logged-out state. For full isolation, create a separate context, which has its own cookie jar.

Vibium is created by Jason Huggins. This is an independent tutorial — see the official Vibium site and GitHub repo for canonical docs.

Related guides