all repos — sz-chrome-remote-extension @ ae0e6d4ea16c8232957d84c226c9c874c7c5f1c1

pi-chrome, patched to drive a signed-in browser on another host through a broker, with an MCP server

feat: lazy-register chrome tools until /chrome authorize

Defer all pi.registerTool() calls until /chrome authorize fires.

Previously, 18 chrome_* tool definitions + chrome-profile-bridge
primer consumed ~5K tokens/turn even when Chrome control locked.

Changes:
- Add chromeToolsRegistered flag (default false)
- Wrap all pi.registerTool() calls in registerChromeTools(pi)
- Only register tools when authorizeFor() runs
- Make before_agent_start conditional: primer injected only when
  tools registered AND authorized
- No tools exist in context until user explicitly allows it

Saves ~5,000 tokens/turn when Chrome control is locked.
Dani Bednarski 49581958+DaniBedz@users.noreply.github.com
Sun, 17 May 2026 00:24:02 +1000
commit

ae0e6d4ea16c8232957d84c226c9c874c7c5f1c1

parent

4739dce965041f72da917794b6d3122d01904f45

2 files changed, 36 insertions(+), 0 deletions(-)

jump to
M extensions/chrome-profile-bridge/index.ts → extensions/chrome-profile-bridge/index.ts

@@ -463,6 +463,7 @@

const bridge = new ChromeProfileBridge(DEFAULT_HOST, DEFAULT_PORT); let backgroundDefault = false; let chromeAuthorizedUntil: number | "indefinite" | undefined; + let chromeToolsRegistered = false; const authSummary = (): string => { if (chromeAuthorizedUntil === "indefinite") return "authorized indefinitely";

@@ -526,6 +527,9 @@ }

}); pi.on("before_agent_start", (event) => { + if (!chromeToolsRegistered || !chromeControlAuthorized()) { + return { systemPrompt: event.systemPrompt }; + } const primer = ` <chrome-profile-bridge> Chrome control is available through the chrome_* tools via a companion Chrome extension installed in the user's normal Chrome profile. Tools target the existing signed-in profile: no remote-debug port, no throwaway profile.

@@ -649,6 +653,7 @@ if (!ok) {

ctx.ui.notify("Chrome control remains locked.", "info"); return; } + registerChromeTools(pi); chromeAuthorizedUntil = until; ctx.ui.notify(`Chrome control authorized for ${label}.`, "info"); updateChromeStatus(ctx);

@@ -850,6 +855,10 @@ ctx.ui.notify(`Unknown subcommand '${head}'. Try: /chrome authorize | revoke | status | doctor | onboard | background.`, "warning");

} }, }); + + function registerChromeTools(pi: ExtensionAPI): void { + if (chromeToolsRegistered) return; + chromeToolsRegistered = true; pi.registerTool({ name: "chrome_launch",

@@ -1384,4 +1393,6 @@ const result = await authorizedBridgeSend("page.upload", withBackground({ ...params, paths }), DEFAULT_TIMEOUT_MS, signal);

return { content: [{ type: "text", text: `Uploaded ${paths.length} file(s) to ${params.uid ?? params.selector}` }], details: { result: result as Json } }; }, }); + } + }
A package-lock.json

@@ -0,0 +1,25 @@

+{ + "name": "pi-chrome", + "version": "0.15.21", + "lockfileVersion": 3, + "requires": true, + "packages": { + "": { + "name": "pi-chrome", + "version": "0.15.21", + "license": "MIT", + "peerDependencies": { + "@earendil-works/pi-coding-agent": "*", + "typebox": "*" + }, + "peerDependenciesMeta": { + "@earendil-works/pi-coding-agent": { + "optional": true + }, + "typebox": { + "optional": true + } + } + } + } +}