更新 playwright_automation 和 screenshots 服务

This commit is contained in:
2025-12-14 22:04:05 +08:00
parent a346509a5f
commit dac06d187e
2 changed files with 39 additions and 29 deletions

View File

@@ -1375,24 +1375,13 @@ class PlaywrightAutomation:
# 先保存到临时文件
temp_filepath = filepath + '.tmp'
# 获取iframe并截取其完整内容
iframe = self.get_iframe_safe()
if iframe:
# 对iframe内容进行全页截图
iframe.screenshot(
path=temp_filepath,
type='jpeg',
full_page=True,
quality=100
)
else:
# 回退到主页面截图
self.main_page.screenshot(
path=temp_filepath,
type='jpeg',
full_page=True,
quality=100
)
# 截图:默认截取主页面(包含左侧菜单/顶部栏等整体界面)
self.main_page.screenshot(
path=temp_filepath,
type='jpeg',
full_page=True,
quality=100
)
# 验证文件是否成功创建且大小合理
if not os.path.exists(temp_filepath):

View File

@@ -117,18 +117,40 @@ def take_screenshot_for_account(
else:
bz = 2 # 应读
target_url = f"{base}/admin/center.aspx?bz={bz}"
automation.main_page.goto(target_url, timeout=60000)
current_url = getattr(automation.main_page, "url", "") or ""
if "center.aspx" not in current_url:
raise RuntimeError(f"unexpected_url:{current_url}")
# 目标:保留外层框架(左侧菜单/顶部栏),仅在 mainframe 内部导航到目标内容页
iframe = None
try:
automation.main_page.wait_for_load_state("networkidle", timeout=30000)
iframe = automation.get_iframe_safe(retry=True, max_retries=5)
except Exception:
pass
try:
automation.main_page.wait_for_selector("table.ltable", timeout=20000)
except Exception:
pass
iframe = None
if iframe:
iframe.goto(target_url, timeout=60000)
current_url = getattr(iframe, "url", "") or ""
if "center.aspx" not in current_url:
raise RuntimeError(f"unexpected_iframe_url:{current_url}")
try:
iframe.wait_for_load_state("networkidle", timeout=30000)
except Exception:
pass
try:
iframe.wait_for_selector("table.ltable", timeout=20000)
except Exception:
pass
else:
# 兜底:若获取不到 iframe则退回到主页面直达
automation.main_page.goto(target_url, timeout=60000)
current_url = getattr(automation.main_page, "url", "") or ""
if "center.aspx" not in current_url:
raise RuntimeError(f"unexpected_url:{current_url}")
try:
automation.main_page.wait_for_load_state("networkidle", timeout=30000)
except Exception:
pass
try:
automation.main_page.wait_for_selector("table.ltable", timeout=20000)
except Exception:
pass
navigated = True
except Exception as nav_error:
log_to_client(f"直达页面失败,将尝试按钮切换: {str(nav_error)[:120]}", user_id, account_id)
@@ -269,4 +291,3 @@ def take_screenshot_for_account(
)
if not submitted:
screenshot_callback(None, "截图队列已满,请稍后重试")