v1.7.4 auto 默认顺序改为优先 playwright、其次 agent-browser
- 按大爷要求调整: auto 优先 playwright(Python, domcontentloaded更宽容), 其次 agent-browser(Rust) - capture_webpage + smart_capture 的 auto 选路同步调整 - 新增对称兜底: playwright 失败自动切 agent-browser 重试(原 agent-browser超时→playwright 逻辑保留) - /api/backends 与前端选择器说明同步更新(auto label/priority)
This commit is contained in:
@@ -955,7 +955,7 @@ async def smart_capture_playwright(url, cfg, wait_time, viewport):
|
||||
def smart_capture(url, cfg, wait_time, viewport, backend="auto"):
|
||||
"""按需截图总入口:滚动截图 + 视觉大模型实时判断,返回拼接长图"""
|
||||
if backend == "auto":
|
||||
backend = "agent-browser" if AGENT_BROWSER_AVAILABLE else "playwright"
|
||||
backend = "playwright" if PLAYWRIGHT_AVAILABLE else "agent-browser"
|
||||
|
||||
if backend == "agent-browser":
|
||||
result = smart_capture_agent_browser(url, cfg, wait_time, viewport)
|
||||
@@ -1002,10 +1002,10 @@ def capture_webpage(
|
||||
"""
|
||||
# 选择后端
|
||||
if backend == "auto":
|
||||
if AGENT_BROWSER_AVAILABLE:
|
||||
backend = "agent-browser"
|
||||
elif PLAYWRIGHT_AVAILABLE:
|
||||
if PLAYWRIGHT_AVAILABLE:
|
||||
backend = "playwright"
|
||||
elif AGENT_BROWSER_AVAILABLE:
|
||||
backend = "agent-browser"
|
||||
else:
|
||||
return {"success": False, "error": "No browser backend available. Install agent-browser or playwright."}
|
||||
|
||||
@@ -1049,9 +1049,19 @@ def capture_webpage(
|
||||
)
|
||||
loop.close()
|
||||
result["backend"] = "playwright"
|
||||
return result
|
||||
except Exception as e:
|
||||
return {"success": False, "error": str(e)}
|
||||
result = {"success": False, "error": str(e)}
|
||||
# playwright 失败(auto 默认优先它)→ 自动切 agent-browser 兜底重试
|
||||
if (not result.get("success") and AGENT_BROWSER_AVAILABLE):
|
||||
try:
|
||||
fb = capture_with_agent_browser(
|
||||
url, action, scroll_times, scroll_delay, full_page, viewport, wait_time
|
||||
)
|
||||
fb["backend"] = "agent-browser"
|
||||
result = fb
|
||||
except Exception:
|
||||
pass
|
||||
return result
|
||||
|
||||
elif backend == "chrome-cdp":
|
||||
# 连接已打开的 Chrome(需 --remote-debugging-port=<cdp_port>),归一化为单结果
|
||||
@@ -1111,11 +1121,12 @@ def api_backends():
|
||||
"default": "auto",
|
||||
"available": available,
|
||||
"unavailable": unavailable,
|
||||
"priority": available + unavailable,
|
||||
# auto 优先 playwright,其次 agent-browser,再 chrome-cdp
|
||||
"priority": ["playwright", "agent-browser", "chrome-cdp"],
|
||||
"labels": {
|
||||
"auto": "自动(推荐:优先 agent-browser,打开超时自动回退 Playwright)",
|
||||
"agent-browser": "agent-browser(Rust 版,反爬强、快,默认首选)",
|
||||
"playwright": "Playwright(Python 版,domcontentloaded 更宽容,慢页面更稳)",
|
||||
"auto": "自动(推荐:优先 Playwright,失败自动回退 agent-browser)",
|
||||
"playwright": "Playwright(Python 版,domcontentloaded 更宽容,慢页面更稳,默认首选)",
|
||||
"agent-browser": "agent-browser(Rust 版,反爬强、快,备选)",
|
||||
"chrome-cdp": "Chrome CDP(连接已打开的 Chrome,需 --remote-debugging-port 启动)"
|
||||
}
|
||||
})
|
||||
|
||||
@@ -630,7 +630,7 @@
|
||||
<option value="auto">加载中…</option>
|
||||
</select>
|
||||
<small id="backendHint" style="color: #666; display: block; margin-top: 4px;">
|
||||
自动 = 优先 agent-browser,打开页面超时自动回退 Playwright(推荐)
|
||||
自动 = 优先 Playwright,失败自动回退 agent-browser(推荐)
|
||||
</small>
|
||||
</div>
|
||||
|
||||
@@ -753,7 +753,7 @@
|
||||
"scroll_times": 3, // 可选:加载动态内容
|
||||
"scroll_delay": 1000, // 可选:滚动间隔
|
||||
"full_page": true, // 可选:全页截图
|
||||
"backend": "playwright", // 可选:playwright / agent-browser
|
||||
"backend": "auto", // 可选:auto(默认,优先playwright,失败回退agent-browser) / playwright / agent-browser / chrome-cdp
|
||||
"caller": "news-tracker", // 可选:调用者标识(历史记录里显示,默认游客)
|
||||
"call_method": "api", // 可选:调用方式 web/api(缺省自动判定)
|
||||
"viewport": {"width":1280,"height":700},
|
||||
|
||||
Reference in New Issue
Block a user