safari-background-mcp
Drives the user's real Safari browser in the background: opens unselected tabs, navigates, interacts with page elements, reads content, takes screenshots, and manages tabs without stealing focus or using the user's active tabs.
This server does not currently have a deployable release on Glama. Follow the repository's setup instructions to install and configure it for your MCP client, including any required credentials and local dependencies.
An MCP server that lets AI agents (Claude Code, Claude Desktop, Cursor, …) drive your real Safari — with your logins, cookies and extensions — entirely in the background.
🫥 Never steals focus, never switches your Space. Agent tabs open as unselected background tabs in an existing Safari window — no window is created (creating one makes macOS jump to another desktop when you work in a full-screen app), and nothing you see changes. All actions are DOM events inside the page; Safari is never activated. A focus guard hands focus back if macOS ever brings Safari forward.
🔒 Never touches your tabs unless you explicitly address one: without an agent tab, actions refuse to run instead of falling back to your active tab. Pinned tabs (which Safari mirrors into every window) are protected from closing.
⚡ Fast. One persistent
osascriptbridge instead of a process per call: ~15 ms per Safari round-trip, 70–200 ms for a typical snapshot or read.🪶 Context-frugal. 26 tools in ~5k tokens of definitions (~3.4k with
SAFARI_MCP_TOOLS=core). Compact snapshots with stable refs, change reports after actions instead of full page dumps, text search inside pages, small cropped screenshots.🧩 No extension, no WebDriver, no Xcode. Just Node and a Safari setting.
See it work
An agent signs up on a web page. On the left — what happens inside the agent's background tab (real Safari screenshots taken by safari_screenshot). On the right — the exact tool calls and what the agent gets back. The whole time Safari stayed behind the terminal; a watchdog checks the frontmost app on every call.
Seven calls, about 3.5 s of Safari work. Notice what the agent does not get: page dumps. After each action it gets a short diff — ~ [e5] radio "Starter Free" [ ], + ## You're on the list! — so a long session stays cheap.
Related MCP server: safari-mcp-server
How it compares
this server | WebDriver-based (safaridriver, Playwright WebKit) | Extension-based Safari MCPs | Chrome DevTools / Playwright MCP | |
Your real profile & logins | ✅ | ❌ separate automation session | ✅ | ❌ by default |
Works without stealing focus | ✅ by design | — | partially (restores focus afterwards) | ❌ on macOS |
Install |
| built-in, but isolated | build/enable an extension | separate browser |
Tool definitions | ~5k tokens | — | up to 90+ tools | ~14–19k tokens |
Actions report what changed | ✅ diff | ❌ | snapshot diff on request | full snapshot |
Requirements
macOS with Safari, Node.js 20+
Safari → Settings → Advanced → Show features for web developers, then Develop → Allow JavaScript from Apple Events
On first use macOS asks to allow your terminal / Claude app to control Safari (Automation). Screenshots additionally need Screen Recording.
press_keywithreal: trueneeds Accessibility.
Install
Claude Code:
claude mcp add safari -- npx -y safari-background-mcpClaude Desktop / Cursor / any MCP client (mcpServers config):
{
"mcpServers": {
"safari": { "command": "npx", "args": ["-y", "safari-background-mcp"] }
}
}From source:
git clone https://github.com/AlexZai007/safari-background-mcp.git
cd safari-background-mcp && npm install
claude mcp add safari -- node "$PWD/server.mjs"Then ask your agent something like “open my GitHub notifications in Safari and summarize them” — it will use your existing login, in a background tab.
Tools
Tool | What it does |
| Open a URL in an unselected background tab and wait for load |
| Go to a URL, or back / forward / reload; waits for load |
| Windows and tabs, marking the agent window and the current tab |
| Target another tab (optionally show/activate it) |
| Close a tab or the whole agent window; pinned tabs are protected |
| Interactive elements with stable refs ( |
| Find elements by text / label / role / selector → refs (cheaper than a snapshot) |
| Page content as compact markdown or text; |
| Cleaned HTML (no scripts/styles/svg) of the page or an element |
| Click (also double/right/modifiers); waits for navigation; reports new tabs and DOM changes |
| Hover (JS events) to open menus/tooltips |
| Type into inputs/textareas/contenteditable (React-safe); |
| Fill many fields (text, selects, checkboxes) in one call |
| Native or custom (ARIA) dropdowns, checkboxes, radios, switches |
| Keys with emulated default actions (Enter submits, Tab moves focus, …) |
| Scroll the page or the SPA's inner scroll container, or to an element |
| Drag and drop between elements |
| Attach local files to a file input / drop zone without the system dialog |
| Run JS (expression, function or body with |
| Wait for text / selector / URL / network idle (or disappearance) |
| Viewport or element screenshot, captured without bringing Safari forward |
| New console messages, JS errors, failed resources, CSP violations |
| fetch/XHR log with status and timing; optional response bodies |
|
|
| localStorage / sessionStorage / cookies |
| Several tool calls in one round-trip |
Elements can be addressed by ref (from snapshot/find), CSS selector (pierces open shadow DOM and same-origin iframes), visible text (+ role), or form label; index picks the N-th match. Tabs are addressed by window_id + tab_index; when omitted, the tab used last is targeted.
> safari_snapshot
Form fixture — http://127.0.0.1:58077/form.html
scroll 0/0px
# Sign up
[e1] textbox "Full name"
[e2] textbox "Email address"
[e3] password "Password"
[e4] textbox "Bio"
[e5] combobox "Country" ="Choose…" {Choose…|United States|Canada|Germany}
[e6] checkbox "I accept the terms" [ ]
[e7] radio "Free" [x]
[e8] radio "Pro" [ ]
[e9] editable "Notes"
[e10] button "Create account"
> safari_fill {"fields":[{"label":"Full name","value":"Ada"},{"label":"Country","value":"Canada"},{"ref":"e6","value":true}]}
✓ textbox "Full name" ="Ada"
✓ combobox "Country" ="Canada"
✓ checkbox "I accept the terms" [x]
no changes in interactive elements
> safari_click {"text":"Add item"} (on another page)
clicked button "Add item"
changes since last snapshot:
+ [e31] button "Item 1"Configuration
Env var | Default | Meaning |
|
|
|
|
|
|
|
| Where the agent window id is remembered, so restarts and parallel sessions reuse one window |
How it works
src/jxa/bridge.js— JXA side: window/tab addressing, background tabs, optional agent window, focus guard; newline-delimited JSON over stdin/stdout.src/bridge.mjs— Node side: request queue, per-call timeouts, automatic restart of a hung bridge.src/page/runtime.js— injected once per document: element refs, snapshot/diff, actions, readers, console/network/dialog capture.src/safari.mjs— tab targeting (agent tabs vs. user tabs), navigation and load detection, settle-after-action logic.src/tools/*— tool definitions;src/server.mjs— registry, profiles,safari_batch.
Limitations
These come from automating Safari without an extension or WebDriver:
Events are synthetic (
isTrusted = false). Sites that require trusted input or CSS:hovermay not react;press_key {real: true}sends real keystrokes but briefly brings Safari forward.Popups opened from synthetic clicks are blocked by Safari; the server opens
target=_blanklinks and blockedwindow.openURLs in a background tab itself.Closed shadow roots and cross-origin iframes are not reachable. HttpOnly cookies are invisible.
Console/network capture starts when the server first touches a page; earlier messages are missed (
safari_network {resources: true}lists earlier resources).Screenshots need the window to be on the current Space (macOS does not render windows of inactive Spaces). A background tab is shown in its window for ~0.3 s during the capture and then switched back.
Background tabs are throttled by Safari (timers,
requestAnimationFrame), so some animations run slower there.Safari internal pages (favorites, settings) and PDFs cannot run scripts.
Development
npm test # unit tests (no Safari needed; bridge tests need macOS)
npm run test:e2e # end-to-end tests in your real Safari, in a background window
STRICT_FOCUS=1 npm run test:e2e # also fail if Safari became frontmost during a call (run hands-off)
node test/client.mjs new_tab '{"url":"https://example.com"}' snapshot '{}' # poke the server manuallyThe README media is reproducible: node docs/demo/demo.mjs --frames <dir> saves the Safari frames and docs/demo/make-safari-gif.sh <dir> docs/media/safari-demo.gif turns them into the GIF, vhs docs/demo/terminal.tape records the terminal (needs vhs); the banner and diagram are SVG sources in docs/media/src.
The e2e suite runs in a separate agent window (plus one test of the default background-tab mode), serves local fixture pages (forms, dialogs, shadow DOM, iframes, drag-and-drop, uploads, SPA routing, slow pages) and runs every tool against them while a watchdog records which app is frontmost.
License
MIT
Tool Schema Changelog
Recent tool additions, removals, and schema changes observed during successful MCP inspections.
Loading tool schema changelog…
This server cannot be deployed
Maintenance
Related MCP Connectors
Programmatic headless browser sessions: create, interact, browse, and extract - rendered in a real
Stealth web automation for AI agents. Login, signup, navigate, screenshot.
Stealth web automation for AI agents. Login, signup, navigate, screenshot.
Hosted browser for AI agents: screenshots, post-JS DOM, console, WCAG. No install, no API key.
Related MCP Servers
- AlicenseBqualityAmaintenanceNative Safari browser automation for AI agents. 80 tools via AppleScript — zero overhead, keeps logins, runs silently in background. Drop-in alternative to Chrome DevTools MCP with 40-60% less CPU/heat on Apple Silicon.981,510 npm252MIT
- AlicenseAqualityAmaintenanceDrives your real, logged-in Safari session on macOS to navigate, read page content, click elements, and fill forms via JXA.9MIT
- FlicenseNot gradedqualityBmaintenanceLets AI agents drive your real, already-logged-in browsers on macOS in the background without stealing focus, organizing work into tab groups, reading pages as compact accessibility snapshots, and saving repeatable scenarios. Supports Chrome, Edge, Brave, Yandex Browser, and Safari, with per-agent isolation and automatic tab cleanup.-
- AlicenseBqualityBmaintenanceEnables AI agents to drive background Chrome tabs and native macOS apps through a compact single-tool, stateful REPL with persistent element UIDs, churn-free diffs, and parallel multi-agent cursors. Performs zero-focus, zero-cursor-movement automation including Accessibility and Vision OCR fallbacks for custom-rendered windows.11,008 PyPI30AGPL 3.0