refactor(browser): rebuild browser tooling on official browser-use patterns - #209
Merged
Conversation
…patterns - Dispatch all actions through the browser-use event bus (ClickElementEvent, TypeTextEvent, ScrollEvent, SendKeysEvent, SelectDropdownOptionEvent, ClickCoordinateEvent, NavigateToUrlEvent, SwitchTabEvent) so library watchdogs handle waiting, scroll-into-view, new-tab switching and validation, instead of hand-rolled CDP calls - Use the official DOM serializer (dom_state.llm_representation) for the element tree and extract_clean_markdown for page content (no LLM call) - Report url/title/tabs/scroll position like the official <browser_state> - Capture console output via CDP Runtime.consoleAPICalled/exceptionThrown (window.console.logs never existed); execute JS via Runtime.evaluate with real console semantics and exception reporting - Drop site-specific icon-font hacks and the custom selector-map formatter - Remove legacy PlaywrightBrowser engine (per-view LLM extraction), the BROWSER_ENGINE setting, and playwright/markdownify dependencies - Fix mockserver browser scenario to use 1-based element indexes Co-authored-by: Simpleyyt <simpleyyt@gmail.com>
PlanActFlow no longer round-trips to the Planner after a successful complete_step, so the canned update_plan response was consumed by the summarizer and surfaced as 'Unknown tool: update_plan', cutting the scenario short before deliver_result. Co-authored-by: Simpleyyt <simpleyyt@gmail.com>
…tterns
Restores BROWSER_ENGINE (browser_use default / playwright) with a rewritten
PlaywrightBrowser that emits the same tool payload shape as the browser-use
engine:
- Markdown content via markdownify (drops the per-view LLM extraction call)
- Visible interactive elements as 1-based [index]<tag ... /> lines with
[Start of page]/[End of page] markers and scroll position in pages
- Console captured with native page.on('console'/'pageerror') listeners
(window.console.logs never existed); console_exec surfaces JS exceptions
- New-tab auto-switch after clicks, and clicking a <select> advises
browser_select_option, matching the browser-use engine behaviour
Co-authored-by: Simpleyyt <simpleyyt@gmail.com>
Simpleyyt
marked this pull request as ready for review
August 18, 2026 17:18
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
背景
浏览器基础设施此前偏离主流做法:手写 CDP 鼠标事件、自定义 selector-map 格式化、针对单个网站的 icon-font hack(leaftools.net 计算器)、永远返回空的
window.console.logs控制台读取,以及 Playwright 引擎每次browser_view都调用一次 LLM 做"页面抽取"。改动
browser-use 引擎(默认):对照官方
Tools(browser_use/tools/service.py,0.13.7)重写NavigateToUrlEvent/ClickElementEvent/ClickCoordinateEvent/TypeTextEvent/ScrollEvent/SendKeysEvent/GetDropdownOptionsEvent/SelectDropdownOptionEvent/SwitchTabEvent,由库的 watchdog 处理等待、滚动到可见、<select>校验与新标签页自动切换(与官方_detect_new_tab_opened一致)。get_browser_state_summary()+dom_state.llm_representation()([index]<tag ... />树),并按官方<browser_state>消息格式补充 url/title/tabs/滚动位置与[Start of page]/[End of page]标记。extract_clean_markdown(),纯函数、无 LLM 调用。Runtime.consoleAPICalled/Runtime.exceptionThrown采集;browser_console_exec改用Runtime.evaluate,支持任意表达式并上报异常。_ICON_CLASS_SYMBOLS、_get_node_hint)与自定义_format_selector_map。Playwright 引擎:按主流模式(Playwright MCP 风格)重建并保留
markdownify纯函数转换。[index]<tag ... />行 +[Start of page]/[End of page]标记 + 滚动位置,两个引擎载荷完全同构、可互换。page.on("console"/"pageerror")监听采集;console_exec上报 JS 异常。<select>提示改用browser_select_option,与 browser-use 引擎行为一致。BROWSER_ENGINE配置保留:browser_use(默认)/playwright。其他
update_plan轮次(现在的PlanActFlow步骤成功后不再回访 Planner,这条会被 summarizer 收到并报Unknown tool,导致场景提前中断)。测试
真实 CDP 集成测试 — 两个引擎同一套 25 项检查全部通过(沙盒 Chrome,覆盖 navigate / view(元素树 + Markdown + 滚动位置)/ 按索引与坐标点击 / 输入 + Enter / 下拉选择 / 组合键 / 滚动 / 控制台采集与 JS 异常 / 截图 / 新标签自动切换 /
<select>提示 / restart):全栈 e2e(mockserver browser 场景):前端发起任务,11 个浏览器工具依次执行,Computer 面板显示 example.com 截图,最终输出 "Browser tool test finished.",无 UI 错误。
browser_tools_e2e_mock_scenario.mp4
后端 pytest(auth/file)与
main基线结果完全一致(16 failed / 17 passed,均为预先存在的测试环境鉴权配置问题,与本改动无关)。To show artifacts inline, enable in settings.