Commit Graph
7 Commits
Author SHA1 Message Date
yetone 8f69ca29c4 browser: Magpie Browser acts like a person and stays out of the user's tabs
The owner, 11-05: Magpie Browser interrupts the user's own browsing, and
driving Discord with it gets the account flagged by Discord's bot check,
which never happened under Claude's Chrome extension.

What a site could see, and what changed (extension 0.1.6):
- CDP's Runtime domain was on in every tab, which bot checks look for.
  It is now off until browser_console is asked for (on localhost, 127.x,
  [::1], *.localhost and *.test it is on from the start, as before).
  The first console call says it reads the console from then on.
- Every read and helper (the clickable scan's getComputedStyle and
  querySelectorAll on each element, focus, readyState, innerText,
  scroll position) ran in the page's own world, where a page's patched
  functions see each call. They now run in an isolated world of the
  extension's (Page.createIsolatedWorld, DOM.resolveNode in it).
  browser_evaluate stays in the page's world, since the agent's script
  is for the page's JavaScript.
- A click jumped to an element's exact middle. The mouse now moves along
  a curved, eased path to a spot drawn around the middle, then presses
  and lets go at uneven timings. Hover and drag go the same way.
- Text went in with Input.insertText, with no key events. It is now
  typed a key at a time with US key codes, Shift held for capitals and
  symbols, at a typist's uneven rhythm (35s at most for a whole text).
  Chinese, Japanese and Korean come through an IME composition, emoji
  through insertText, and a newline as Shift+Enter so a chat box doesn't
  send early. A field's old text is cleared with Backspace only when it
  has some, and submit waits a moment before Enter.
- A scroll was one wheel event. It is several notches now.
- Actions follow each other at a person's pace (350 to 1600ms apart),
  and the debugger stays attached for 5 minutes idle, not 2, so Chrome's
  bar doesn't come and go between calls.

The user's tabs:
- A call naming one of the user's own tabs (one outside every Magpie
  group) now opens that page in a background tab of the agent's own, in
  its group, and the agent is told so; naming it again goes on in that
  copy. This is how Claude's extension keeps to its own group.
- tab_close refuses a tab of the user's.
- A tab an action opens always goes in the agent's group, and a page
  that opens a window of its own gives focus back to the window the user
  was in.
- The tool's instructions said calls go to the tab the user is looking
  at. They now say the agent works in tabs of its own, that naming the
  user's tab copies it, that steps take a person's time, and how the
  console starts.

Run at this head (rebased on fe61503e6), on mote with Chromium 1248
(Chrome for Testing, --headless=new):
- gofmt -l clean; go vet for darwin, linux and windows on
  internal/gateway and internal/browserext
- go test ./internal/browserext: ok
- go test -run TestBrowser ./internal/gateway, with
  MAGPIE_BROWSER_CHROME: 21 of 21 pass, the six real-browser tests among
  them
- New TestBrowserActsLikeAPerson, on shop.example (mapped to the test's
  site, so not a developer's host). It checks that the page never sees
  its getComputedStyle, querySelectorAll, elementFromPoint or focus
  called. It checks that a click is trusted, off the middle, after 4 or
  more mousemoves. It checks a keydown per character at uneven gaps,
  Shift for capitals, and Chinese through compositionend, both in a
  textarea and in a contenteditable chat box. In that chat box a newline
  doesn't send and submit does. It also checks that a 600px scroll is 3
  or more wheel events, that the console is off until asked for, and
  that a named user tab is copied into the group and left as it was.

Broken by hand, each red in that test:
- Runtime always on: console says nothing about starting
- a click at the exact middle with one mousemove: "landed on the middle
  (-0.5, -0.375)" and "moved 1 times"
- insertText for typing: 0 keydowns, even gaps, no Shift, no composition
- the clickable scan in the page's world: the page saw 27 calls
- naming the user's tab acting in it: "doesn't say is the user's own tab"

Not tried:
- The real Discord or a real account. Whether Discord's check now passes
  is not something a test here shows. The reasons it is likely to are the
  differences above, and that they match what Claude's extension does
  (Runtime only when asked, reads outside the page's world, a move before
  each click).
- Headful (MAGPIE_BROWSER_HEADFUL=1) on mote. TestBrowserLeavesTheUsersTabAlone
  fails at random steps there on origin/main fe61503e6 too, even right
  after a plain navigate, because the window counts as hidden on mote's
  idle display (#5513).
- Edge, Windows and Linux Chrome.

The user reloads Magpie Browser in chrome://extensions to get 0.1.6.
2026-11-06 18:41:38 +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 7e201ce20d browser: one tool, browser, whose action says what to do
magpie-browser listed 17 tools (11,483 bytes of schema in every request);
it now lists one, browser, whose action picks what to do (4,087 bytes).
The old tool names are still accepted on tools/call, and text the
extension writes about browser_X now says "the X action".

Any action takes screenshot: true and returns the page after it, as a
1024px-wide JPEG (q70), so an agent sees the page without a second call.

Run on mote at this head: go test -tags nogui -run Browser
./internal/gateway/ with a real Chromium: ok, including
TestBrowserToolActionsInARealBrowser. TestBrowserToolCallsTheExtensionsTool
went red with the name rewrite taken out by hand and with the downscale
taken out (2880x1800 stays 2880x1800). gofmt clean; go vet -tags nogui for
darwin, linux and windows ok. Not tried: Claude Code and Codex using the
one tool against a live gateway.
2026-11-02 06:40:03 +08:00
yetone da23fcb169 browser: frames from other sites are read and acted on; failures say their kind
A page's cross-site iframes (out-of-process frames) were missing from the
snapshot: Page.getFrameTree on the parent doesn't list them, so a checkout
form or a login inside such a frame couldn't be read or clicked. The
snapshot now adds each frame whose session was auto-attached under its
parent (t.frameOf), and actions on its refs go to that frame's session.

A failed action now says its kind (STALE_REF, DIALOG_OPEN, LOAD_FAILED,
PAGE_BLOCKED, WAIT_TIMEOUT, OUTCOME_UNKNOWN, BAD_ARGS ...) with what to try next, and an action
settles on the DOM going quiet before it says done. Extension 0.1.3.

Run on mote at this head: go test -tags nogui -run Browser
./internal/gateway/ ./internal/browserext/ with a real Chromium
(MAGPIE_BROWSER_CHROME, Chrome for Testing 1234): ok, including
TestBrowserFramesAndFailuresInARealBrowser. Red on the old code ("no
textbox Card"); the settle taken out by hand made it red ("doesn't say
done"). gofmt clean; go vet -tags nogui for darwin, linux and windows ok.
Not tried: a real site's payment iframe in the owner's own Chrome.
2026-11-02 06:40:03 +08:00
yetone 726544eed7 browser: with two browsers connected, an agent lists them and picks one
With Magpie Browser in two browsers (Chrome and Edge, or two profiles),
every call went to the last to connect and nothing said there was another
(packinggoodsllc_07668 on Discord: which one is controlled?).

- Each connection gets an id (b1, b2, in connect order) and a name from its
  User-Agent (Edge, Opera, Vivaldi, Yandex say so; Brave, Arc and other
  Chromium browsers read as Chrome).
- browser_tabs action browsers lists them, * on the one calls go to; action
  use with browser (an id, or a name only one has) moves this session's
  calls there. Other sessions stay where they were; a browser that
  disconnects drops every session's pick of it.
- With two or more connected, browser_tabs list says whose tabs it lists.
  The default is still the last to connect.

Run (mote-run): go test ./internal/gateway -run Browser ok (new
TestBrowserMCPPicksAmongBrowsers, TestBrowserName); go vet, GOOS=linux and
windows go vet ./internal/gateway ok.
Broken by hand: forSession ignoring the pick, the new test red ("s1 after
picking chrome: ... b2's tabs (Edge 141)").
Not tried: two real browsers at once; the GUI still shows only the last
connected browser.
2026-11-01 16:10:16 +08:00
yetone 3cb8b17312 browser: two agents at once each work in a tab and tab group of their own
Magpie Browser kept a tab per session, but a session with no tab took the
tab the user was looking at, so two agents started together worked in one
tab, and every agent's tabs went in one "Magpie" group
(packinggoodsllc_07668 on Discord).

- A session whose first call finds the shown tab held by another session
  gets a new background tab of its own.
- Each session's tabs go in a group of its own: "Magpie", then "Magpie 2",
  "Magpie 3" beside other live sessions (session → group kept in
  storage.session with the tabs).
- browser_tabs list marks another session's tab ~ and names each tab's group.
- A link that opens a tab moves the session that clicked it (t.by), not the
  first session found holding the old tab.
- Instructions and the popup's hint say so; extension 0.1.1.

Run (mote-run, MAGPIE_BROWSER_CHROME = Playwright's Chrome for Testing
1234): TestBrowserToolsInARealBrowser and the new
TestBrowserSessionsApartInARealBrowser (two sessions, real tabs and groups)
ok; go test ./internal/browserext; ./internal/gateway -run
'Browser|MCP|Hub'; GOOS=linux and windows go vet of gateway, library,
browsermcp, browserext ok.
Broken by hand: the new test against the old background.js is red ("both
sessions work in t803211511").
Not tried: real Chrome/Edge with a user profile, a person watching the
groups; t.by with two sessions (the click test has one).
2026-11-01 16:10:16 +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