fix: 展开所有可滚动容器以截取完整页面内容

在截图前通过JavaScript展开所有带overflow的容器,确保full_page能够捕获全部内容。

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
This commit is contained in:
2025-12-14 16:17:51 +08:00
parent 94ceb959c7
commit a3497f2921

View File

@@ -1361,31 +1361,43 @@ class PlaywrightAutomation:
# 先保存到临时文件 # 先保存到临时文件
temp_filepath = filepath + '.tmp' temp_filepath = filepath + '.tmp'
# 尝试展开iframe以显示全部内容 # 展开所有可滚动容器,使内容完全显示
try: try:
self.main_page.evaluate("""() => { self.main_page.evaluate("""() => {
const iframe = document.querySelector('iframe[name="mainframe"]'); // 移除body和html的高度限制
if (iframe) { document.documentElement.style.height = 'auto';
try { document.documentElement.style.overflow = 'visible';
const iframeDoc = iframe.contentDocument || iframe.contentWindow.document; document.body.style.height = 'auto';
const contentHeight = Math.max( document.body.style.overflow = 'visible';
iframeDoc.body.scrollHeight,
iframeDoc.documentElement.scrollHeight, // 查找所有可能的滚动容器并展开
2000 const expandScrollable = (el) => {
); if (!el || el === document.documentElement) return;
iframe.style.height = contentHeight + 'px'; const style = window.getComputedStyle(el);
iframe.style.minHeight = contentHeight + 'px'; if (style.overflow === 'auto' || style.overflow === 'scroll' ||
iframe.style.maxHeight = 'none'; style.overflowY === 'auto' || style.overflowY === 'scroll') {
// 调整父容器 el.style.height = 'auto';
let parent = iframe.parentElement; el.style.maxHeight = 'none';
while (parent && parent !== document.body) { el.style.overflow = 'visible';
parent.style.height = 'auto'; }
parent.style.maxHeight = 'none'; if (el.parentElement) expandScrollable(el.parentElement);
parent.style.overflow = 'visible'; };
parent = parent.parentElement;
} // 从表格开始向上展开
} catch(e) {} const table = document.querySelector('table.ltable, .ltable, table');
} if (table) expandScrollable(table.parentElement);
// 展开所有带overflow的元素
document.querySelectorAll('*').forEach(el => {
const style = window.getComputedStyle(el);
if ((style.overflow === 'auto' || style.overflow === 'scroll' ||
style.overflowY === 'auto' || style.overflowY === 'scroll') &&
el.scrollHeight > el.clientHeight) {
el.style.height = el.scrollHeight + 'px';
el.style.maxHeight = 'none';
el.style.overflow = 'visible';
}
});
}""") }""")
time.sleep(0.5) time.sleep(0.5)
except Exception: except Exception: