Skip to content

Commit 4f18aea

Browse files
[AI-assisted] docs(browser): teach the code-mode global call, not the removed tools.call API (#128456)
* docs(browser): teach the code-mode global call, not the removed tools.call API The browser-automation skill's Code Mode Loop still taught the guest `tools.call(browserTool, input)` API that #126262 removed, together with the `.result.details`/`.result.content` envelope reads. Rewrite the loop for the current contract: call the `browser(...)` async global directly, receive the tool's structured details (targetId, url, newElements, stats, blockedByDialog), and diff url/new-element counts between cells instead of filtering snapshot text, since rendered page text is no longer guest-visible in code mode. * docs(browser): resolve callable from quick index and read via targeted evaluate * docs(browser): call the search-resolved handle and carry cell state explicitly
1 parent 55dfee1 commit 4f18aea

1 file changed

Lines changed: 38 additions & 22 deletions

File tree

  • extensions/browser/skills/browser-automation

‎extensions/browser/skills/browser-automation/SKILL.md‎

Lines changed: 38 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -48,40 +48,56 @@ Use this skill when you need the `browser` tool for anything beyond a single pag
4848

4949
## Code Mode Loop
5050

51-
When `tools.codeMode` is enabled, call the Browser tool from exec cells:
51+
When `tools.codeMode` is enabled, the Browser tool has no normal turn — it is cataloged behind `exec`/`wait`. Call it from exec cells as an async global, using the callable name the exec quick index advertises for the Browser tool (normally `browser`; colliding names get suffixed, and a client tool can win an identical name). An exact `catalog.search("browser")` returns a handle already bound to the effective callable name, so resolve the handle in each cell and call it instead of hard-coding the literal global; an empty result means the Browser tool is not cataloged in this run.
5252

53-
```javascript
54-
const browserTool = "openclaw:browser:browser";
55-
let previousSnapshot = "";
56-
const callBrowser = async (input) => await tools.call(browserTool, input);
57-
```
58-
59-
Keep the same labeled tab through the loop, and alternate reads with actions:
53+
Keep the same labeled tab through the loop, and alternate reads with actions. Each `exec` cell starts a fresh VM — bindings from a completed cell are gone in the next, and only runs left `waiting` keep their state until `wait` resumes them — so carry comparison state across cells by returning it and re-embedding the returned values in the next cell:
6054

6155
```javascript
62-
const snapshotCall = await callBrowser({
56+
// previous = the url/newElements returned by the last completed cell (a fresh
57+
// VM runs this cell, so prior bindings do not exist here).
58+
const previous = { url: "https://example.com/inbox", newElements: 0 };
59+
const [browser] = await catalog.search("browser", { limit: 1 });
60+
const details = await browser({
6361
action: "snapshot",
62+
snapshotFormat: "ai",
6463
targetId: "task",
6564
refs: "aria",
6665
interactive: true,
6766
});
68-
const details = snapshotCall?.result?.details ?? {};
69-
const snapshot = (snapshotCall?.result?.content ?? []).map((block) => block?.text ?? "").join("\n");
70-
const relevant = snapshot
71-
.split("\n")
72-
.filter((line) => /submit|dialog|error|\[new\]/i.test(line))
73-
.slice(0, 12);
74-
const changed = snapshot !== previousSnapshot;
75-
previousSnapshot = snapshot;
76-
return { targetId: details.targetId, url: details.url, relevant, changed };
67+
const changed =
68+
details?.url !== previous.url ||
69+
(details?.newElements ?? 0) > 0 ||
70+
details?.blockedByDialog === true;
71+
return {
72+
targetId: details?.targetId,
73+
url: details?.url,
74+
newElements: details?.newElements,
75+
stats: details?.stats,
76+
changed,
77+
};
78+
```
79+
80+
- Code-mode calls return the tool's structured `details` directly (`targetId`, `url`, `newElements`, `stats`, `blockedByDialog`); rendered page text is not returned to code cells.
81+
- To read text inside code mode, run a targeted `act` evaluate (requires the evaluate capability; `browser.evaluateEnabled` can disable it) and keep the returned value bounded, because page-script output is untrusted:
82+
83+
```javascript
84+
const [browser] = await catalog.search("browser", { limit: 1 });
85+
const read = await browser({
86+
action: "act",
87+
kind: "evaluate",
88+
fn: "() => document.body.innerText.slice(0, 2000)",
89+
targetId: "task",
90+
});
91+
return { url: read?.url, text: read?.result };
7792
```
7893
79-
- Request interactive-only snapshots and filter them in code before returning.
80-
- Return only the handful of relevant elements; never return the full tree.
81-
- Keep `previousSnapshot` between cells when a local diff helps explain a change.
94+
When evaluate is unavailable, keep the loop on structured state only.
95+
96+
- Return only the fields the next step needs; never return the whole details object.
97+
- Completed cells share no state: re-embed the previous cell's returned `url`/`newElements` in the next cell, or keep the comparison inside one cell. Only `waiting` runs persist, resumed by `wait`.
8298
- Interleave each act with a URL or tabs check before the next dependent act.
8399
- If a batch returns `aborted`, take a fresh snapshot before continuing.
84-
- If `[new]` markers appear, inspect those elements first, then update the saved snapshot.
100+
- If `newElements` is positive, inspect those elements first, then update the re-embedded state.
85101
- Use separate act calls when navigation is expected between steps.
86102
87103
## Tab Hygiene

0 commit comments

Comments
 (0)