Commit Graph
6 Commits
Author SHA1 Message Date
yetone 4f3ec591ae browser: an extension older than magpie's is to be reloaded, says the sheet and the agent
magpie rewrites the extension's folder when an older one connects, but
Chrome runs what it loaded until the extension is reloaded on
chrome://extensions or the browser starts again, so a user who never does
either stays on the old code. Now that is said:

- Library → Magpie Browser: under "Connected to your browser · 0.1.8" a
  line says "Magpie Browser 0.1.9 is ready: reload Magpie Browser on
  chrome://extensions (edge://extensions in Edge)." Looked at from another
  computer (the zip install), it says to download it again, unzip it over
  the old folder and reload it. /api/library/browser has outdated.
- The agent: the first browser answer on such a connection starts with a
  line telling it to have the user reload it (or download it again, for
  one connected with a gateway key). Once a connection.

The extension still isn't made to reload itself: an unpacked one that
calls chrome.runtime.reload() doesn't come back (the finding in
browser.go's hello).

The fake extension in the gateway's tests now says magpie's own version
(it said 0.1.0, which every test would now be told about).

Run (on mote):
- internal/gateway TestBrowser* (new TestBrowserSaysTheExtensionIsOlder,
  TestBrowserSaysNothingOfACurrentExtension), ok.
- internal/gui TestBrowser* (new TestBrowserStateOutdated), ok.
- GUI: library-browser-setup, library-browser-away, library-browser-ask,
  browser-access, i18n-keys in Chromium and WebKit, every language, at
  1100 and 420 wide: 127 of 128. The red is i18n-keys "a plugin's words
  are its own" for three keys this change doesn't touch, red on main and
  filed (#5332, #5482, #5426).
- go vet for darwin, linux (nogui) and windows; gofmt -l clean.

Broken by hand:
- the once-a-connection check removed: TestBrowserSaysTheExtensionIsOlder
  red ("s1's next answer" has the note again).
- the sheet's line never shown: library-browser-setup red, 20 of 20.
- Outdated without Connected: TestBrowserStateOutdated red.

Not tried: the whole GUI suite before this push (run next), and a real
Chrome with an older extension loaded by hand.
2026-11-09 06:57:40 +08:00
yetone e1eeeed734 browser: the extension's key connects Magpie Browser and nothing else; own needs this computer; a key turned off closes its browser
483b131ef wrote a full-access gateway key ("Magpie Browser") into the
extension zip in Downloads. Anyone with a copy of the zip could use every
model, MCP server and stat, and, with own = key == OwnBrowserKey(), could
connect from another machine as this computer's own browser and receive
this computer's agents' browser calls (page data out, prompt injection
in). A keyed WebSocket also stayed open after its key was turned off.

- access: Key.Browser / Identity.Browser. A browser key is also ReadOnly
  (so a magpie from before reads it as read-only) and never issues keys.
  access-key and issuer-key refuse it. ScopeBrowser(id) holds an existing
  key to the browser with the same secret; the sharing key is never
  scoped. Current(who) says whether a key Check took is still on by the
  same secret (Identity carries the secret's SHA-256, set on the legacy
  sharing-key fallback too, so a legacy caller's identity is the same
  before and after its migration).
- gateway readOnlyGuard, the one place every route passes after the key
  is known: a browser key gets 403 gateway_key_browser_only on every
  pattern except GET /v1/magpie/browser/extension.
- own: the key must be OwnBrowserKey() and the request local(r)
  (loopback peer, not proxied, not the page port).
- browserConn keeps its key's identity. call() refuses a connection whose
  key is no longer Current, and a 5s watcher closes it (1008).
- gui browserKey: a new key is made Browser; the recorded key is reused
  only once ScopeBrowser holds it.
- GUI key row: "Browser only" tag (zh, zh-TW, ja, de), no access toggle.
  CLI prints "browser" access. agent gatewayTakes skips a browser key.

Old data: an existing "Magpie Browser" key (OwnBrowserKey) is rescoped in
place, same id and secret, when the gateway starts (ScopeOwnBrowserKey)
and again on the next extension download. Installed extensions keep
connecting with no reinstall. Every copy of an old zip loses models, MCP,
stats and writes, and from another machine it is no longer this
computer's browser. A user who downgrades reads the key as read-only.
Keys a user made themselves are untouched.

Regression, filed as #5529: Magpie in Docker with the host's Chrome
reaches the container from 172.17.0.1, not loopback, so its agents no
longer get the host's browser as their own. #5529 proposes pairing in
its place. docs/reference.md and site docker pages (en, zh, ja) say so.

Docs: docs/subsystems/gateway-routing.md (browser key), library.md
(Download), docs/reference.md (Docker), site/public/docs{,/zh,/ja}/docker.html.

Run on mote at origin/main 2000ae439 + this change:
- gofmt -l internal cmd: empty.
- go vet darwin, GOOS=windows, GOOS=linux -tags nogui over access,
  gateway, gui, agent, cli: ok.
- go test -tags nogui -count=1 -timeout 45m ./internal/gateway
  ./internal/gui ./internal/access ./internal/library ./internal/agent
  ./internal/cli: all ok except access's
  TestLegacyLANFallbackBeforeMigration, red from this change (the legacy
  fallback had no secret sum). Fixed here, then ./internal/access in full:
  ok.
- GUI, 21 files (gateway-key-*, i18n-*, library-browser-*), chromium and
  webkit, every language: 332 of 334. The 2 reds fail the same on
  origin/main 6f5d48ea0 run alone: i18n-keys "a plugin's words are its
  own" (#5332, #5426, #5482) and gateway-key-models' 560px width check
  (#4081, commented).

Rebased onto 6f5d48ea0 (remote_prove: a new POST /v1/magpie/prove route
and edits to readonly.go and gateway.go, so not a -run rerun): gofmt -l
empty, vet on all three ok, go test -count=1 ./internal/gateway
./internal/access ok, ./internal/gui -run Browser ok. A browser key gets
403 on the prove route too (TestBrowserKeyEveryRoute walks every pattern).

Broken by hand, each red on mote:
- guard off: TestBrowserKeyEveryRoute (/v1/ 200, /v1/models read_only
  not browser_only).
- no migrate: TestBrowserKeyEveryRoute (/v1/models 200).
- own without local(r): TestOwnBrowserKeyIsThisComputers.
- no watcher: TestBrowserKeyOffClosesItsBrowser (stayed connected).
- no Current check in call(): TestBrowserKeyOffClosesItsBrowser.
- Current ignoring the secret: TestCurrent.
- gui reuse without ScopeBrowser / new key without Browser:
  TestBrowserExtensionDownload (both).

Not tried: a real Chrome with the real extension, a real Docker
container, a real old key in a live HOME, the TUI. No CLI test for the
"browser" access word. Tests reach no network (httptest, loopback only).
2026-11-06 22:11:02 +08:00
yetone 483b131ef0 browser: magpie in Docker uses the host's own browser, through a key the page hands out
noahhrreion ran magpie in a container and its Magpie Browser never
connected. The host's Chrome dials ws://127.0.0.1:3425/v1/magpie/browser/
extension, which reaches the container from the bridge (172.17.0.1). That
is not loopback, so the gateway refused it (403). The browser MCP also
refused every caller from elsewhere, and the hub marked the browser
HereOnly. The extension's folder under the container's HOME can't be
loaded by the host's browser either.

Nothing is opened to the network without a key:

- The extension takes a gateway key: its popup has a Gateway key field,
  and config.js carries KEY (extension 0.1.7). From another computer the
  extension connects only with ?key= of a gateway key that is on, and
  only from the extension's own Origin (checked first). Loopback is
  unchanged, and a page's origin, null, a keyless call or a rebound Host
  are all still refused (TestBrowserExtensionOnlyFromItsOrigin).
- A browser that connects with a key belongs to that key. Sessions are
  tagged key:<id>/... (browserOwner, keyedSession), and a remote caller's
  session is forced to its own key's whatever it names. The relay filters
  every lookup (forSession, all, choose) through browserConn.serves. The
  browser MCP admits a remote caller only with a gateway key; a web page
  is refused as before.
- The key the page makes is recorded as this magpie's own browser's: its
  id goes in settings.Dir()/browser-key, written temp-and-rename. This
  goes by where the key came from, not by its name. A browser connecting
  with it serves this computer's sessions too, so agents inside the
  container use it as they would one on loopback. A record that can't be
  read names no key, so no keyed browser is this computer's.
- Router: magpie mcp browser is HubServer.Keyed. A visitor from
  elsewhere gets it only with a key (HubVisitor.Key), and hubCall names
  its session key:<id>/..., so it reaches only that key's browser.
- GUI: a page whose browser can't reach magpie's folders (InContainer, or
  a page from another computer) is "away". The Magpie Browser sheet's
  button then reads Download the extension. It does a POST to
  /api/library/browser/extension with the page's origin, which answers a
  zip pointed at that origin (3430 passes the gateway's routes on) and
  holding the recorded key's secret. The key is made the first time and
  reused while it is on. The steps (unzip, chrome://extensions, Developer
  mode, Load unpacked) are shown in every language. It is a POST so that
  a link from another site can't mint a key.
- Docs: reference.md (Docker), subsystems/library.md and mcp-router.md,
  and site docker.html in en, zh and ja.

Run, at this tree rebased on origin/main 6302f88bf, on mote:
- gofmt -l, go vet ./..., GOOS=linux go vet -tags nogui ./...,
  GOOS=windows go vet ./..., and darwin, linux and windows builds:
  clean, all ok
- go test -tags nogui -run 'Browser|Hub|OwnBrowser' ./internal/gateway/,
  and the whole of internal/library, internal/gui and internal/browserext:
  ok (gateway 2.4s, library 166s, gui 104s, browserext 0.3s)
- GUI tests library-browser-away (new: every language, Chromium and
  WebKit, 1100 and 420 wide), library-browser-setup, library-browser-ask,
  i18n-keys and i18n-en-no-cjk: 115 pass. One red, i18n-keys "a plugin's words are its own", is for three
  strings this change doesn't touch and is already filed (#5332, #5426,
  #5482)

Real use, in Docker Desktop on xiaomi-gpu (Windows 11): this tree's
Dockerfile image, run as `web --addr 0.0.0.0:3430` with 3425 and 3430
published to the host's localhost. The host's Node and Playwright Chromium:
- signed in to the page, which says away:true;
- downloaded the zip (GATEWAY "ws://localhost:3530" and a KEY), twice,
  getting the same key both times;
- a keyless /mcp/magpie/browser call from the host got 401;
- loaded the unzipped extension with --load-extension. The container's log
  says "Magpie Browser 0.1.7 connected with gateway key 12d2702a…" and
  /api/library/browser says connected:true;
- an MCP client on the host with that key listed b1 (Chrome 151), opened
  http://localhost:3531/ (served on the host) and read "hello from the
  host";
- a second gateway key made in the container got "isn't connected with
  this gateway key";
- a curl inside the container to 127.0.0.1:3425/mcp/magpie/browser with no
  key listed the host browser's tabs, the host page included.

Broken by hand, each red:
- forSession left unfiltered;
- a remote session not forced to its key;
- no Origin check on a keyed connect;
- hubCall not prefixing the session;
- Keyed given to a visitor with no key;
- the old MCP guard;
- browserKey not reusing the key;
- the away peer check removed;
- serves("") without own (TestOwnBrowserKeyIsThisComputers,
  TestOwnBrowserKeyUnreadable);
- OwnBrowserKey reading the wrong file (the gateway tests and
  TestBrowserExtensionDownload).

Not tried:
- the reporter's own setup (their compose file and Chrome);
- a real agent's MCP client calling the browser from the host. Node's
  fetch sends Sec-Fetch-Mode: cors, which fromBrowser counts as a web page
  and refuses. The e2e used node's http instead. Whether an agent's MCP
  client built on fetch is hit by this is not checked; filed as #5522.
- Edge, Brave and Firefox;
- a remote page over https/wss through a proxy.

What the user does: update magpie and publish 3425 and 3430. In the web
UI open Library -> Magpie Browser -> Download the extension, unzip it and
Load unpacked in chrome://extensions. An extension 0.1.7 already loaded
can take the address and key in its popup instead.

Reported-by: noahhrreion (Discord)
2026-11-06 20:06:15 +08:00
yetone 51fa4b7eb0 browser: agents work in tabs of their own, behind the user's
The owner: Magpie Browser "老是会代替掉用户正在浏览的网页". A call that
named no tab, from a session with none, took the tab the user had in
front and navigated it away under them. Now:

- such a call opens a new tab of the session's (about:blank), behind the
  shown one, in its Magpie tab group, in the window used last, or an
  unfocused window of its own when none is open (open() in background.js);
- browser_tabs new / tab_new open behind too; front: true shows the tab,
  for when the user asked to see it (background is still taken, and is
  now the default);
- a screenshot of a tab behind shows it for the picture, then gives the
  window back the tab the user had in front;
- a link with target=_blank clicked in a tab behind: Chrome shows the new
  tab and names the user's shown tab as its opener. It is still followed,
  grouped in the session's group, and the user's tab is put back in front.
- the tool descriptions say so; the user's tabs are acted in only when a
  call names one.

Extension 0.1.4. When an older one connects, the gateway writes this
magpie's over its folders (browserext.Refresh; only folders already
written, never a newer one's: browserext.Older), so the browser picks it
up when it starts again or on the extension's reload in
chrome://extensions. Before, only opening Library's Browser page did. The
dir helpers moved from gui to browserext for it.

Tried and dropped: telling the extension to chrome.runtime.reload()
itself. In Chrome for Testing 1234 on mote an unpacked extension that
calls it never comes back (headless and headful, --load-extension and
CDP Extensions.loadUnpacked, with an onInstalled listener), which would
leave the user with none until a restart.

Run on mote at 1e1068c86 + this:
- MAGPIE_BROWSER_CHROME=Chrome for Testing 1234, go test -run Browser -v
  ./internal/gateway: ok, 16 passed, including the new
  TestBrowserLeavesTheUsersTabAlone (navigate, link to a new tab, tab new,
  screenshot, tab_new: the user's about:blank tab stays + and unchanged,
  the agent's in [Magpie]) and TestBrowserOlderExtensionsFolderWritten.
- go test ./internal/browserext (TestOlder, TestRefreshWritesOnlyWrittenFolders): ok.
- go test ./internal/gui: one red, TestMainWindowCorners/macOS_26_SDK,
  filed as #3949 (macOS 27 on mote), not touched here.
- gofmt -l; GOOS=darwin/linux/windows go vet of the three packages: clean.

Broken by hand: TestBrowserLeavesTheUsersTabAlone with origin/main's
background.js is red ("navigated the user's tab"). The link case was
found by TestBrowserToolsInARealBrowser going red on the first version.

Not tried: the user's own Chrome (headful Chrome with real sign-ins),
Edge and Arc; Windows and Linux browsers.
2026-11-03 23:48:36 +08:00
yetone e42ee3b816 library: Magpie Browser's extension sits in ~/Magpie Browser Extension, dragged from the sheet onto chrome://extensions
The owner, on the v0.1.2442 sheet: the extension was written to
~/.config/magpie/browser-extension, a hidden folder no one can find to
choose in Load unpacked.

- Set up writes it to "Magpie Browser Extension" in the home folder
  (browserExtDir), where Finder and Explorer show it, and shows it
  selected in its parent (open -R on the Mac, explorer /select, on
  Windows, the home folder on Linux) rather than opened, to drag from.
- On the Mac the sheet has the folder itself: a press on it that moves
  hands the folder to the system's drag (POST /api/library/browser/drag,
  filedrag_darwin.go: beginDraggingSession from the key window with a
  file URL and the folder's icon, only while the button is still down),
  so it drops onto chrome://extensions as from Finder. Chromium's
  extensions page loads a dropped folder as unpacked
  (drag_and_drop_handler.ts: entry.isDirectory -> loadUnpackedFromDrag),
  with Developer mode on, which step 2 asks for.
- Elsewhere step 3 says to drag the folder from the window that opened,
  or Load unpacked and choose it.
- Old installs: a browser that loaded the hidden folder still does, and
  that folder is kept up to date as long as it has a manifest; the sheet
  offers set up again, into the new folder.

Run at ace58117a on mote: go vet ./internal/gui (darwin), GOOS=linux -tags
nogui and GOOS=windows vet; library-browser-setup and i18n-keys GUI
tests, 46 of 46 (5 languages, Chromium and WebKit, 1100 and 420 wide,
with and without the drag: a click posts no drag, a press that moves
posts one); internal/cli parity tests ok. At df0320156: go test
./internal/gui ./internal/cli, cli ok, gui red only in
TestMainWindowCorners, which is #3949 and red the same at df0320156
without this change.
Not tried: the native drag by hand into a real Chrome (no way to drive
a mouse drag here), and Explorer's /select on the Windows box.
2026-11-01 17:28:15 +08:00
yetone 0e90572274 browser: Magpie Browser, agents use the user's own browser and its sign-ins
The owner asked for a browser-use MCP of magpie's own, so an agent's
browser keeps working when Claude Code switches accounts, and asked that
it act in the browser the user uses every day: a fresh Playwright
profile is signed in to nothing.

Magpie Browser is an MV3 extension (internal/browserext, ID
dmlhojidlfnkgamkekjhacgkpanbkeko, pinned by its key) that the user loads
once in Chrome, Edge, Arc, Brave or another Chromium browser. It holds a
WebSocket to the gateway's /v1/magpie/browser/extension and carries out
each tool call with chrome.debugger (the DevTools protocol) in the user's
own tabs. The socket is taken only from this computer, with a loopback
Host (no DNS rebinding) and the extension's own Origin; a page or another
extension that connected in its place would be handed every call.

Agents reach it at /mcp/magpie/browser (Streamable HTTP) or through
`magpie mcp browser` (stdio), and the Library's MCP market lists it as
Magpie Browser, opt-in. Like the image server it is magpie's own, but it
is never served to another computer, shared and with a key or not, and
never to a web page, since it acts as the user wherever they are signed
in. 17 tools: navigate (url, back, forward, reload), snapshot (an
accessibility tree with refs, interactive-only on ask), click, type,
press, select, hover, drag, upload, scroll, wait (text, gone, seconds),
dialog, evaluate, text, screenshot (page, full page, element; JPEG or
PNG), console and tabs (list, new, select, close). Each agent session
goes on in its own tab; a link that opens a tab is followed, and a
dialog a click opens is said in the reply.

The Library's sheet for it has Set up the extension…, which writes the
extension to ~/.config/magpie/browser-extension pointed at this gateway
and shows the folder, the three steps to load it, and whether the
browser is connected, polled while the sheet is open.

Run:
- TestBrowserToolsInARealBrowser: the extension magpie writes, loaded in
  a real Chrome for Testing 141 (Playwright's chromium-1234, headless=new)
  with --load-extension, connects, and all 17 tools act in a real tab of
  a fixture site. Green on mote (macOS 27), on xiaomi-gpu (Windows 11,
  win-run) and in magpie-desktop (Ubuntu 24.04, wsl-run). Under a test
  HOME Chrome needs --use-mock-keychain / --password-store=basic, or the
  extension's storage waits on a keychain and it never connects.
- go test ./internal/gateway -run 'Browser|ReadOnly|Image', ./internal/
  browserext, ./internal/browsermcp, ./internal/library, ./internal/gui
  -run 'Library|Browser', ./internal/cli on mote.
- GUI: library-browser-setup.test.cjs (new) in Chromium and WebKit, en,
  zh, zh-TW, ja, de, at 1100 and 420 wide: 22/22. With i18n-keys and
  every library*.test.cjs: 915 pass, 1 fail, i18n-keys' "Unmarked",
  red on main since 5787d758a (#4524, fixed in the next commit).
- gofmt -l, go vet ./..., GOOS=linux go vet -tags nogui ./..., GOOS=windows
  go vet ./... on mote.
- Again at this commit, rebased on 2e9df9b1b: gofmt -l, the vet trio,
  ./internal/gui -run 'Budget|Size', ./internal/proc (exec guard),
  ./internal/usage, ./internal/browserext, ./internal/browsermcp, and
  i18n-keys (0 fail with the next commit). The full go test ./... runs
  in magpie-desktop (Linux) as this is pushed; mote had another
  session's suite running.

Broken by hand, each red, then restored:
- browser_click's dispatch in background.js turned into a no-op: the
  E2E test is red at "clicked Ada".
- the extension socket's Origin check, its loopback-Host check and
  local(): TestBrowserExtensionOnlyFromItsOrigin red for each.
- browserMCP's local()/fromBrowser() guard: TestBrowserMCPGuarded red.
- a tool dropped from background.js: TestBrowserToolsAreTheExtensions red.
- the sheet's steps left shown once connected: the GUI test is red.

Not tried: loading it by hand (Load unpacked) in the owner's own daily
Chrome or Edge and driving a site they are signed in to; Arc, Brave and
Edge themselves (only Chrome for Testing); Firefox and Safari, which
have no chrome.debugger and are not supported. Chrome shows its "is
debugging this browser" bar while a tab is being driven; that is
Chrome's and cannot be hidden.
2026-11-01 02:29:55 +08:00