支持复用色花堂常驻浏览器会话

- 为 sehuatang_push 增加远程调试端口附着能力,优先复用常驻 Chrome 浏览器\n- 区分外部浏览器与自管理浏览器,避免任务结束时误关闭用户正在使用的浏览器\n- 从插件配置和任务 payload 读取浏览器复用参数,并补充 browser 配置项说明
This commit is contained in:
liuwei
2026-04-27 15:41:36 +08:00
parent d177448d94
commit a8070a7214
3 changed files with 151 additions and 43 deletions

View File

@@ -46,6 +46,23 @@ class SehuatangPushPlugin(MessagePluginInterface):
super().__init__()
self.feature = self.register_feature()
def _build_browser_config(self, payload: Dict[str, Any]) -> Dict[str, Any]:
"""整理浏览器配置,优先读取插件配置,再允许任务 payload 做局部覆盖。"""
# 这里把浏览器连接参数集中整理出来,
# 目的是让调度入口不需要关心太多细节,同时兼容后续从后台任务动态覆盖端口。
browser_cfg = dict(self._config.get("browser", {}) or {})
if "reuse_existing_browser" in payload:
browser_cfg["reuse_existing_browser"] = payload.get("reuse_existing_browser")
if "debugger_host" in payload:
browser_cfg["debugger_host"] = payload.get("debugger_host")
if "debugger_port" in payload:
browser_cfg["debugger_port"] = payload.get("debugger_port")
if "allow_launch_fallback" in payload:
browser_cfg["allow_launch_fallback"] = payload.get("allow_launch_fallback")
return browser_cfg
def initialize(self, context: Dict[str, Any]) -> bool:
return True
@@ -94,11 +111,15 @@ class SehuatangPushPlugin(MessagePluginInterface):
payload = context.get("payload") or {}
at_user = str(payload.get("at_user", "Jyunere") or "Jyunere").strip()
browser_config = self._build_browser_config(payload)
strict_reuse_existing_browser = bool(browser_config.get("reuse_existing_browser")) and not bool(
browser_config.get("allow_launch_fallback", True)
)
# 兼容历史逻辑:优先使用 undetected 方案,失败后回退普通抓取。
try:
ok, path = await asyncio.to_thread(pdf_file_path_undetected)
if not ok:
ok, path = await asyncio.to_thread(pdf_file_path_undetected, browser_config)
if not ok and not strict_reuse_existing_browser:
ok, path = await asyncio.to_thread(pdf_file_path)
if not ok:
return {"success": False, "summary": "PDF 生成失败", "detail": {}}