---
slug: "how-to-get-session-cookie-of-browser-use-its-httponly"
title: "Obtain HttpOnly=True Session Cookies from Services Logged in via Browser-Use"
description: "Pitfalls when passing `--headless` or `-profile` to Selenium Firefox, and the right way to use `selenium.webdriver.FirefoxOptions`."
url: "https://www.ytyng.com/en/blog/how-to-get-session-cookie-of-browser-use-its-httponly"
publish_date: "2025-05-21T03:10:36.553Z"
created: "2025-05-21T03:10:36.553Z"
updated: "2026-05-11T13:21:39.658Z"
categories: ["Python"]
keywords: ""
featured_image_url: "https://media.ytyng.com/resize/20250521/5af8cc37ff9d4dfc82599fb19d21a7a5.png.webp?width=768"
has_video: true
has_music: true
video_urls: ["https://media.ytyng.net/ytyng-blog/322/featured-video-1.mp4", "https://media.ytyng.net/ytyng-blog/322/featured-video-2.mp4", "https://media.ytyng.net/ytyng-blog/322/featured-video-3.mp4"]
music_urls: ["https://media.ytyng.net/ytyng-blog/322/featured-music-322-2.mp3?v=3", "https://media.ytyng.net/ytyng-blog/322/featured-music-322-4.mp3"]
lang: "en"
---

# Obtain HttpOnly=True Session Cookies from Services Logged in via Browser-Use

Here is how you can obtain session cookies issued when logging into a web service using `browser-use`.

Session cookies are typically issued with `httponly=true`, so even if you request `browser-use` to "retrieve session cookies," they won't be returned. This is because they cannot be accessed via JavaScript.

If you want to obtain them, you can prepare a `browser_use.Browser` instance in advance and inject it into the `browser-use` Agent, allowing you to handle the Playwright browser instance during processing.

This approach is effective not only for session cookies but also when dealing with finer resources inside the browser.

```python
from browser_use import Agent, Browser
from langchain_openai import ChatOpenAI

DEFAULT_LLM_MODEL = "gpt-4.1-mini"

def get_session_cookies():

    browser = Browser()
    current_cookies = []
    
    async def handle_step(browser_state, agent_output, step_number):
        nonlocal browser, current_cookies
        try:
            # Handle the Playwright instance
            context = browser.playwright_browser.contexts[0]
            current_cookies = list(await context.cookies())
        except Exception as e:
            print(
                'An error occurred while getting cookies: '
                f'{e.__class__.__name__}: {e}'
            )

    _login_prompt = 'Please log into our web service ◯◯.\n\n...'

    async def run_agent():
        agent = Agent(
            task=_login_prompt,
            browser=browser,
            llm=ChatOpenAI(model=DEFAULT_LLM_MODEL),
            register_new_step_callback=handle_step,
        )
        await agent.run(max_steps=5)

    asyncio.run(run_agent())

    # Login complete. Cookies should be obtained here
    print(current_cookies)
```
