How Playwright Works
Playwright is a browser automation framework that controls real browsers (Chromium, Firefox, WebKit) through their respective DevTools protocols. Unlike screenshot-based approaches, Playwright interacts with the browser’s internal APIs to perform actions precisely as a user would.Browser Engines
Playwright MCP supports three browser engines:Chromium
Google Chrome, Microsoft Edge, Brave, Opera
Firefox
Mozilla Firefox
WebKit
Apple Safari
Browser Contexts
A browser context is an isolated browser session with its own cookies, localStorage, and cache. Think of it as an incognito window.Context Isolation
Each context maintains:- Independent cookies and sessions
- Separate localStorage and sessionStorage
- Isolated cache
- Individual permissions and geolocation
Context Options
Configure context behavior throughcontextOptions:
Pages and Tabs
A page represents a single browser tab within a context. Playwright MCP provides tab management tools:When you close the last tab in a context, the browser session ends and all state is lost (unless using persistent profile).
Headed vs Headless Modes
Playwright can run browsers in two modes:Headed (Default)
Visible browser window✓ See what’s happening in real-time✓ Easier debugging✓ Better for development✗ Requires display environment
Headless
No visible window✓ Runs on servers without display✓ Faster execution✓ Lower resource usage✗ Can’t visually inspect
Enabling Headless Mode
Persistent vs Isolated Profiles
Playwright MCP supports two profile management strategies:Persistent Profile (Default)
Browser data is saved to disk and persists between sessions: Storage locations:- Logged-in sessions persist
- Cookies and localStorage remain
- Browser settings saved
- History and bookmarks preserved
Isolated Profile
Browser profile is kept in memory and discarded after the session:- Clean state for each session
- No profile pollution
- Ideal for testing
- Privacy-focused
storage-state file contains cookies and localStorage that will be loaded into the isolated context.
Use persistent profiles for long-running automation tasks. Use isolated profiles for testing or when you need reproducible clean state.
Browser Extension Mode
Connect to an already-running browser instance using the Playwright MCP Bridge extension:- Use your existing logged-in sessions
- Access browser profiles with extensions
- Leverage bookmarks and history
- Work with enterprise browser configurations
Extension mode only works with Chrome and Edge browsers. See the extension installation guide for setup instructions.
CDP Connection
Connect to browsers using Chrome DevTools Protocol:- Connect to remote browser instances
- Use cloud browser services
- Debug running applications
- Enterprise browser management
Device Emulation
Emulate mobile devices and tablets:- Screen size and pixel ratio
- User agent string
- Touch event support
- Mobile viewport meta tag
iPhone 15
393×852, iOS Safari
iPad Pro
1024×1366, iOS Safari
Pixel 7
412×915, Chrome Mobile
Initialization Scripts
Inject custom JavaScript before pages load:Init Script (JavaScript)
Runs in every page before its scripts execute:Init Page (TypeScript)
Executes on the Playwright page object during setup:Session Recording
Capture browser sessions for debugging and analysis:Trace Recording
Playwright traces include:- DOM snapshots at each step
- Network requests and responses
- Console messages
- Screenshots
- Action timeline
Video Recording
Record video of the browser session:Session Logs
Save detailed session logs:Next Steps
Accessibility Snapshots
Learn how Playwright captures page structure
Configuration Reference
Explore all configuration options

