Driving a logged-in browser
To act inside a session that's already authenticated (an SSO'd internal app, a site behind a login you don't want to automate), attach to a running Chrome over the DevTools protocol instead of launching a fresh one.
Attach to a running Chrome
Start Chrome with remote debugging exposed, then attach:
playwright-cli attach --cdp=http://localhost:9222The CLI also accepts a channel name when the browser isn't already listening:
playwright-cli attach --cdp=chrome
playwright-cli attach --cdp=msedgeOnce attached, every command drives that real browser and its existing cookies and tabs. detach releases it and leaves the browser running; close would terminate it.
Persisting auth without attaching
When you control the launch, a persistent profile carries cookies between runs:
playwright-cli open --persistent
playwright-cli open --profile=/path/to/profile # explicit directoryOr capture and replay storage state (cookies + localStorage):
playwright-cli state-save auth.json # after logging in once
playwright-cli state-load auth.json # in a later runNotes
attachrepoints the session slot to the attached browser. If adefaultsession was already in use, attaching reuses that slot — name the session (-s=work) to keep them separate.- The underlying Chrome keeps running after
detach; re-attach with the same--cdpendpoint to resume.