feat(browser): specialize browser prompt - #151
Conversation
There was a problem hiding this comment.
2 issues found across 2 files
Prompt for AI agents (unresolved issues)
Check if these issues are valid — if so, understand the root cause of each and fix them. If appropriate, use sub-agents to investigate and fix each issue separately.
<file name="packages/bcode-browser/skills/browser-execute/SKILL.md">
<violation number="1" location="packages/bcode-browser/skills/browser-execute/SKILL.md:15">
P3: The connect condition is ambiguous and diverges from the code's actual gate. `browser-execute.ts` `ensureCloudConnected` auto-connects only when `V4_RUN_ID` is set AND at least one of `BU_CDP_WS`/`BU_CDP_URL` is set. The phrasing "When both `V4_RUN_ID` and `BU_CDP_WS` or `BU_CDP_URL` are set" can be read as `BU_CDP_URL` alone being sufficient, which would make an agent skip `session.connect()` in a run that lacks `V4_RUN_ID`. Rephrase to require `V4_RUN_ID` and at least one CDP endpoint var.</violation>
<violation number="2" location="packages/bcode-browser/skills/browser-execute/SKILL.md:40">
P2: In the Drive example, `navigation.errorText` is checked only after `await loaded`. When navigation fails, CDP never emits `Page.loadEventFired`, so `await loaded` times out after 15s with a misleading "Timeout waiting for Page.loadEventFired" and the real `errorText` is hidden. Check `errorText` immediately after `navigate`, before awaiting the load waiter.</violation>
</file>
Reply with feedback, questions, or to request a fix.
Fix all with cubic | Re-trigger cubic
| const navigation = await session.Page.navigate({url: "https://example.com"}) | ||
| await loaded | ||
| // Page.navigate resolves even on network errors — its result carries `errorText` when the load failed. | ||
| if (navigation.errorText) throw new Error(navigation.errorText) |
There was a problem hiding this comment.
P2: In the Drive example, navigation.errorText is checked only after await loaded. When navigation fails, CDP never emits Page.loadEventFired, so await loaded times out after 15s with a misleading "Timeout waiting for Page.loadEventFired" and the real errorText is hidden. Check errorText immediately after navigate, before awaiting the load waiter.
Prompt for AI agents
Check if this issue is valid — if so, understand the root cause and fix it. At packages/bcode-browser/skills/browser-execute/SKILL.md, line 40:
<comment>In the Drive example, `navigation.errorText` is checked only after `await loaded`. When navigation fails, CDP never emits `Page.loadEventFired`, so `await loaded` times out after 15s with a misleading "Timeout waiting for Page.loadEventFired" and the real `errorText` is hidden. Check `errorText` immediately after `navigate`, before awaiting the load waiter.</comment>
<file context>
@@ -1,209 +1,72 @@
+const navigation = await session.Page.navigate({url: "https://example.com"})
await loaded
-// Page.navigate resolves even on network errors — its result carries `errorText` when the load failed.
+if (navigation.errorText) throw new Error(navigation.errorText)
-// Evaluate JS in the page.
</file context>
| #### Way 1: connect to the user's running Chrome or Chromium-based browser (real profile, popup-gated). | ||
| Choose when the task involves the user's logged-in sites, current browser state, cookies, saved data, etc. | ||
| Browser Use Cloud API V4 automatically connects and attaches the existing page. When both `V4_RUN_ID` and | ||
| `BU_CDP_WS` or `BU_CDP_URL` are set, start driving immediately; do not call `session.connect()` or `session.use()`. |
There was a problem hiding this comment.
P3: The connect condition is ambiguous and diverges from the code's actual gate. browser-execute.ts ensureCloudConnected auto-connects only when V4_RUN_ID is set AND at least one of BU_CDP_WS/BU_CDP_URL is set. The phrasing "When both V4_RUN_ID and BU_CDP_WS or BU_CDP_URL are set" can be read as BU_CDP_URL alone being sufficient, which would make an agent skip session.connect() in a run that lacks V4_RUN_ID. Rephrase to require V4_RUN_ID and at least one CDP endpoint var.
Prompt for AI agents
Check if this issue is valid — if so, understand the root cause and fix it. At packages/bcode-browser/skills/browser-execute/SKILL.md, line 15:
<comment>The connect condition is ambiguous and diverges from the code's actual gate. `browser-execute.ts` `ensureCloudConnected` auto-connects only when `V4_RUN_ID` is set AND at least one of `BU_CDP_WS`/`BU_CDP_URL` is set. The phrasing "When both `V4_RUN_ID` and `BU_CDP_WS` or `BU_CDP_URL` are set" can be read as `BU_CDP_URL` alone being sufficient, which would make an agent skip `session.connect()` in a run that lacks `V4_RUN_ID`. Rephrase to require `V4_RUN_ID` and at least one CDP endpoint var.</comment>
<file context>
@@ -1,209 +1,72 @@
-#### Way 1: connect to the user's running Chrome or Chromium-based browser (real profile, popup-gated).
-Choose when the task involves the user's logged-in sites, current browser state, cookies, saved data, etc.
+Browser Use Cloud API V4 automatically connects and attaches the existing page. When both `V4_RUN_ID` and
+`BU_CDP_WS` or `BU_CDP_URL` are set, start driving immediately; do not call `session.connect()` or `session.use()`.
-```js
</file context>
Summary
Evaluation evidence
The earlier 106-task experiment bundle improved from 81/106 to 88/106 while agent cost fell from $176.92 to $141.91 and timeouts fell from 6 to 3. Non-cached input per model call fell from about 8,110 to 2,231 tokens.
That run also included a BrowserCode version upgrade and eval-adapter hardening, so it is directional evidence rather than an isolated prompt A/B. This PR ports only the context-reduction changes onto current main. The GPT-5.5 medium-verbosity override is intentionally excluded because it was not isolated.
Verification
Summary by cubic
Specializes the agent’s system prompt for browser tasks and condenses the
browser_executeskill. This reduces token usage while keeping V4 auto-connect, reattach behavior, navigation-error handling, screenshot auto-attach, and timeout guidance. Directionally improved evals (81→88/106), lower cost ($176.92→$141.91), and fewer timeouts (6→3).packages/opencode/src/session/prompt/gpt.txt: Replaces a ~1.5k-word generic prompt with a ~177-word browser-native prompt. Emphasizes bounded CDP calls, persistent session reuse, evidence-backed outputs, and required-field auditing. Removes broad editing/formatting guidance; confirm no workflows depend on that guidance.packages/bcode-browser/skills/browser-execute/SKILL.md: Shrinks1.7k→360 words. Preserves attach and reattach on-32001,Page.navigate.errorTexthandling, screenshot auto-attachment, cache-bustedawait import(...), andERR_TUNNEL_CONNECTION_FAILEDguidance. Removes step-by-step Chrome launch and Browser Use Cloud provisioning examples; verify the remaining connect/attach examples still cover common flows.Rollout
Written for commit 95c9f1c. Summary will update on new commits.