Browser Agent Logins: Sessions, Profiles and Secrets

7 min read

Most useful web tasks happen behind a login. Your orders, your inbox, your company dashboard. So a browser agent needs three things a demo never shows: a session that survives between runs, a way to type a password without the model ever seeing it, and a plan for when a human has to step in. This part tests all three in browser-use 1.0.9, and reads the library's own trust model to see where the protection ends.

Hand-drawn diagram: run 1 logs in and writes cookies and storage into the user_data_dir; run 2 on the same profile is still logged in. Below, sensitive_data maps a name to a value, type_secret(name, id) types the real value, and the model only sees secret:name. Note from the README: Not a sandbox, a guard for an aligned model

Problem: every run starts logged out

A fresh browser has no cookies. If your agent logs in every run, it is slow, it trips login alerts and it may hit two-factor prompts every time. You want the login to stick, the way it does in your own browser.

Solution: point the browser at a profile folder

Chrome keeps cookies, local storage and saved sessions in a user data directory. browser-use 1.0 has three ways to pick one, per the README and migration guide:

OptionWhat it usesStarts with
Browser('chromium')A fresh Chromium with a temp profileNo cookies
Browser('chromium', user_data_dir='/path')Chromium with a folder you keepWhatever that folder holds
Browser('chrome', profile='Work')Your installed Chrome and a real profileYour real logins
Browser()A Browser Use cloud browserNo cookies, unless you use a cloud profile

The migration guide adds one trap: Chrome 136 and later refuse remote debugging on the default user data directory. So point user_data_dir at a separate folder, not your everyday one.

We tested persistence on a small local test page. It has a password field and a "Log in" button that sets a session cookie with a one-day lifetime. Three runs, each a brand-new Agent and a brand-new Browser:

python
import asyncio, shutil
from scripted import run
from browser_use import Browser
PROFILE = '/tmp/bu-demo-profile'
shutil.rmtree(PROFILE, ignore_errors=True)
RUN1 = [
"""new_tab('http://127.0.0.1:18765/login.html'); wait_for_load()
ax = cdp('Accessibility.getFullAXTree')['nodes']
pw = [n for n in ax if n.get('role',{}).get('value') == 'textbox'][0]['backendDOMNodeId']
type_secret('demo_password', pw)
print('field value read back by page JS:', js("return document.getElementById('pw').value"))""",
"""js("document.getElementById('go').click()")
print(js("return document.getElementById('s').textContent"), '| cookie:', js("return document.cookie")[:20])""",
]
RUN2 = ["""new_tab('http://127.0.0.1:18765/login.html'); wait_for_load()
print('cookie in a NEW browser on the same profile:', js("return document.cookie")[:20])"""]
async def main():
    print('##### RUN 1'); await run('log in', RUN1, finish_text='ok', browser=Browser('chromium', user_data_dir=PROFILE),
                                    sensitive_data={'demo_password': 'hunter2-not-real'})
    print('##### RUN 2'); await run('check', RUN2, finish_text='ok', browser=Browser('chromium', user_data_dir=PROFILE))
    print('##### RUN 3 (fresh temp profile)'); await run('check', RUN2, finish_text='ok', browser=Browser('chromium'))
asyncio.run(main())

run() is the small scripted-model helper from Part 4. It feeds these cells to the real browser-use 1.0.9 agent and prints what the model would see. The real log:

Terminal log of the real run. Run 1: type_secret typed the demo password, page JS read the field back and the output shows secret:demo_password; clicking Log in printed logged in and a session cookie. Run 2, a new browser on the same profile, still has the same session cookie. Run 3, a fresh temp profile, has no cookie

What it shows:

  • Run 2 is a new browser process. It still had session=demo-1795875 because the cookie lived in the profile folder.
  • Run 3 used a temp profile and had no cookie. (Its print label still says "same profile" because it reused the same cell text. The empty value is the point.)

Problem: the model should never see your password

If you put a password in the task text, it goes to the model provider, it lands in logs and a prompt injection can ask the model to type it somewhere else.

Solution: named secrets, typed by the harness, redacted on the way back

browser-use passes secrets by name. You give sensitive_data={'demo_password': '...'}. The model is told only the name. It calls type_secret('demo_password', node_id) and the REPL types the real value with key events.

Look at Run 1 again. After typing, the cell asked the page for the field's value with js(...). The page returned the real password. But the output the model got says <secret:demo_password>. The harness redacted it on the way back.

The migration guide's "Trust model for secrets" section lists what is redacted: cell stdout and stderr, errors, finish_from_repl values, checkpoint files, your own tool results, the task text, the final result and telemetry. It also redacts encoded forms: JSON- and HTML-escaped, upper and lower case, reversed, base64, hex and URL-encoded.

A domain-scoped secret goes further. With {'https://site.com': {...}}, the value is typed only while the focused frame's URL, as the browser reports it, matches that site. The guide says a prompt-injected page cannot get it typed on another site, or into another site's iframe on the right page.

sequenceDiagram
  participant U as Your code
  participant L as Agent loop
  participant M as Model
  participant W as REPL worker
  participant P as Page
  U->>L: sensitive_data={'demo_password': value}
  L->>W: value over control channel
  L->>M: "you may type secret: demo_password"
  M->>L: python("type_secret('demo_password', pw)")
  L->>W: run cell
  W->>P: key events with the real value
  P-->>W: js() reads field: real value
  W-->>L: output, value replaced by <secret:demo_password>
  L-->>M: redacted output

Problem: redaction is not a sandbox

The same section of the guide is blunt about the limits. It says "This is not a sandbox". Among the gaps it lists:

  • The values live in the worker process, so model-written Python can read them. A transform the redactor does not know, like rot13 or splitting the value, passes through.
  • Files the code writes itself are never redacted.
  • Screenshots are not redacted. A typed value in a visible field, such as an email or a "show password" field, reaches the model as pixels.
  • The worker runs as your user. It can read files your user can read and, on Linux, other processes' environment through /proc/<pid>/environ, including provider API keys.
  • Browser('chromium') and Browser('chrome', profile=...) listen on a 127.0.0.1 debugging port with no authentication. Any local account can attach while it runs.

Its advice, repeated several times: run untrusted tasks in a container or VM. On a shared machine, use a container, a VM or the cloud browser. Part 11 does that.

Problem: some steps need a human

Two-factor codes, "Allow remote debugging?" prompts, consent screens and payment confirmations are meant for a person. An agent should not try to get past them on its own.

browser-use 1.0 gives you a few honest options, all from the README and migration guide:

  • Log in yourself, then let the agent reuse it. Use Browser('chrome', profile='Work') or a kept user_data_dir. Do the login and 2FA by hand once. Later runs start logged in. With your real Chrome, the guide notes that model-written CDP can read that profile's cookies, so only do this with tasks you trust.
  • Watch the cloud browser. The cloud quickstart says a new cloud browser returns a liveUrl you can open to watch it. The guide warns that the live view, and anyone with that URL, sees what is typed.
  • Stop and continue. The run returns what it has when it hits a wall. You can cancel a run with task.cancel() and give a follow-up with add_new_task(task), which continues the same transcript.
flowchart TD
  A[Agent hits login or 2FA] --> B{Profile already logged in?}
  B -->|yes| C[Continue the task]
  B -->|no| D[Agent stops and reports]
  D --> E[Human logs in once in that profile]
  E --> F[Re-run with the same user_data_dir]
  F --> C

The design idea is simple. The agent never holds the factor that proves you are you. You do that part, once, and the profile carries the result.

The Muse series looks at the same problem for a personal agent, including how a user watches a live session and takes it over: see Giving an Agent a Real Browser Without Losing Control.

Try this

Run the persistence test above, then delete the session cookie by hand in the profile with Chrome DevTools and run Run 2 again. Your agent is now logged out. Real sites do this when a session expires, so plan for it.

Sources