Skip to content

Local-first AI coding agent desktop: Electron + Rust host core + pi Agent Harness + user-installable plugins

fix(browser): require visible panel before browser actions (#1473)

Lan75d42d5fedc1
diff --git a/apps/desktop/resources/plugins/pi.browser/main.js b/apps/desktop/resources/plugins/pi.browser/main.js
index 3722f8664..3dee902b3 100644
--- a/apps/desktop/resources/plugins/pi.browser/main.js
+++ b/apps/desktop/resources/plugins/pi.browser/main.js
@@ -26,8 +26,17 @@ const PLAN_SAFE_ACTIONS = ["navigate", "snapshot", "screenshot", "console"];
export async function onLoad() {
await pi.agent.registerTool({
name: "Browser",
- description:
- "Drive PI-Desktop's work-panel browser via CDP: snapshot the accessibility tree, click/fill by uid, screenshot, evaluate JavaScript, read console output, or send an allowlisted raw CDP method. Call ToolSearch for \"browser\" or \"cdp\" to load this tool. Use BrowserPreview to open a workspace HTML file with live reload.",
+ description: [
+ "Drive PI-Desktop's work-panel browser via CDP.",
+ 'Call ToolSearch for "browser" or "cdp" to load this tool.',
+ "Before any browser operation, ensure the Browser view is open and visible in the work panel.",
+ "Keep the panel visible while working.",
+ "For a workspace HTML file, call BrowserPreview first; it opens and reveals a Browser tab.",
+ "For other URLs, open or activate Browser from the work-panel launcher before navigating.",
+ "If you cannot make the view visible, ask the user to open it and wait before continuing.",
+ "Then snapshot the accessibility tree, click/fill by uid, take screenshots, evaluate JavaScript,",
+ "read console output, or send an allowlisted raw CDP method.",
+ ].join(" "),
risk: "medium",
planSafeActions: PLAN_SAFE_ACTIONS,
schema: {
@@ -36,7 +45,7 @@ export async function onLoad() {
action: {
type: "string",
enum: ACTIONS,
- description: "Operation to run against the visible work-panel guest.",
+ description: "Run only after confirming the Browser view is open and visible in the work panel.",
},
url: { type: "string", description: "http(s) URL for action=navigate." },
path: {
diff --git a/apps/desktop/test/browser-preview-tool.test.mjs b/apps/desktop/test/browser-preview-tool.test.mjs
index 26409b957..10aeb27ff 100644
--- a/apps/desktop/test/browser-preview-tool.test.mjs
+++ b/apps/desktop/test/browser-preview-tool.test.mjs
@@ -21,6 +21,10 @@ const runtimeSource = await readFile(
new URL("../../../packages/agent-runtime/src/runtime.ts", import.meta.url),
"utf8",
);
+const browserPluginSource = await readFile(
+ new URL("../resources/plugins/pi.browser/main.js", import.meta.url),
+ "utf8",
+);
test("sidecar routes main-local tools before the host-core proxy", () => {
// Local tools short-circuit tools.execute; other methods still proxy.
@@ -103,3 +107,26 @@ test("agent runtime exposes BrowserPreview in every mode and prompts for it", ()
// BrowserPreview tool description mentions live-reload behaviour.
assert.match(runtimeSource, /live-reloads/);
});
+
+test("Browser tool prompt requires the work-panel view to stay visible", () => {
+ assert.match(
+ browserPluginSource,
+ /Before any browser operation, ensure the Browser view is open and visible in the work panel/,
+ );
+ assert.match(
+ browserPluginSource,
+ /For a workspace HTML file, call BrowserPreview first; it opens and reveals a Browser tab/,
+ );
+ assert.match(
+ browserPluginSource,
+ /For other URLs, open or activate Browser from the work-panel launcher before navigating/,
+ );
+ assert.match(
+ browserPluginSource,
+ /If you cannot make the view visible, ask the user to open it and wait before continuing/,
+ );
+ assert.match(
+ browserPluginSource,
+ /Run only after confirming the Browser view is open and visible in the work panel/,
+ );
+});
diff --git a/docs/spec/06-delivery/04-e2e-test-plan.md b/docs/spec/06-delivery/04-e2e-test-plan.md
index ac2f82f57..7c3518365 100644
--- a/docs/spec/06-delivery/04-e2e-test-plan.md
+++ b/docs/spec/06-delivery/04-e2e-test-plan.md
@@ -1574,15 +1574,20 @@ identify the platform validation still needed.
- **Preconditions**: Packaged or checkout build with bundled plugins; Agent
session with a workspace HTML file; Plan session available.
- **Steps**: 1) Confirm Plugins lists `pi.browser`, enabled, not uninstallable.
- 2) Open the work panel and launch Browser from plugin views. 3) Ask the
- agent to preview a workspace HTML file (`BrowserPreview`) then snapshot via
- ToolSearch `cdp` / `Browser`. 4) Switch to Plan and call the plugin Browser
- tool. 5) Disable `pi.browser`. 6) Call `BrowserPreview` and click an http(s)
- transcript link. 7) From a third-party or test caller, send
+ 2) With the work panel closed, ask the agent to preview a workspace HTML
+ file (`BrowserPreview`) and verify the Browser tab opens in the visible work
+ panel. 3) Use ToolSearch `cdp` / `Browser` to snapshot and interact while the
+ panel remains visible. 4) For an HTTP(S) URL, verify the agent opens or
+ activates Browser before navigating; if it cannot reveal the view, it asks
+ the user to open it before continuing. 5) Switch to Plan and call the plugin
+ Browser tool. 6) Disable `pi.browser`. 7) Call `BrowserPreview` and click an
+ http(s) transcript link. 8) From a third-party or test caller, send
`Network.getAllCookies` through `pi.browser.cdp`.
- **Expected**: The launcher has no host Browser row. Preview opens the plugin
- view and live-reloads the file. Plugin tool `plugin_pi_browser_Browser` can
- snapshot after ToolSearch. Plan denies the plugin tool
+ view, reveals the work panel, and live-reloads the file. Browser operations
+ are made only while the view is visible; the agent waits for the user to
+ reveal it if necessary. Plugin tool `plugin_pi_browser_Browser` can snapshot
+ after ToolSearch. Plan denies the plugin tool
(`PLUGIN_DISABLED_IN_PLAN`) while `BrowserPreview` remains callable. Disable
hides the view and tools; `BrowserPreview` errors; http(s) chips use
`openExternal`. Cookie CDP is denied. Guest bounds stay inside the plugin