fix: avoid focusing chrome during collection

This commit is contained in:
chengma
2026-07-08 18:03:59 +08:00
parent 8a8d656a58
commit 521d363ab2
7 changed files with 232 additions and 15 deletions
+5 -3
View File
@@ -3,7 +3,7 @@ id: T-562
title: ①采集打开商品页不主动切换 Chrome 前台
phase: 2
deps: [T-203, T-205b, T-560]
status: TODO
status: DONE
created: 2026-07-08
---
@@ -29,11 +29,11 @@ created: 2026-07-08
- `cdp.create_tab_info(url, host=None, background=False)` 增加 `background` 参数。
- 当 `background=True` 时,`Target.createTarget` 参数中带 `background: true`。
- `open_product(..., bring_to_front=False)` 新建商品 tab 时传 `background=True`;复用已有 tab 时不激活。
- 如果 Chrome 版本忽略 `background`,仍至少不再执行 `Page.bringToFront`。
- 如果 Chrome 版本忽略或拒绝 `background`,则退回普通新建 tab,仍至少不再执行 `Page.bringToFront`。
3. **测试**
- editor 单测覆盖:采集调用不发送 `Page.bringToFront`,更新调用仍发送。
- cdp 单测覆盖:`create_tab_info(background=True)` 会把 `background: true` 传给 `Target.createTarget`。
- cdp 单测覆盖:`create_tab_info(background=True)` 会把 `background: true` 传给 `Target.createTarget`,并覆盖 `background` 被拒绝后的普通新建回退。
- 保持失败时自动关闭本轮新建 tab、复用用户已有 tab 不关闭的原语义。
## 验收要点
@@ -50,3 +50,5 @@ created: 2026-07-08
## 执行记录
- 2026-07-08:完成。`editor.open_product()` 增加 `bring_to_front` 参数;①采集调用 `bring_to_front=False`,不主动 `Page.bringToFront`;③更新继续默认前台激活。`cdp.create_tab_info()` 增加 `background` 参数,后台创建失败时自动回退普通新建。已同步 `docs/04-architecture.md` 和 `docs/routes.md`。
- 2026-07-08:验证通过:`python -m ruff check app tests main.py`、`py -3.10 -m compileall app main.py`、`py -3.10 -m unittest discover -s tests`、`git diff --check`。