fix: iframe link click - add allow-popups, use target=_blank

Previous fix injected base target=_top but the sandbox attribute lacked allow-top-navigation, so the browser blocked link clicks and the user had to Ctrl+Click as a workaround. Fix: sandbox allow-same-origin allow-popups + base target=_blank. Links now open in new tab (better UX, no content loss). Also fix deploy/rebuild.ps1 to read jar from target/ instead of deleted deploy/baota/. Add agent_test/ scripts: create_7_test_projects, upload_test_html, manual_package.
This commit is contained in:
2026-06-03 22:32:06 +08:00
parent afcd18c54f
commit 2784c5b36f
7 changed files with 300 additions and 15 deletions
+96
View File
@@ -0,0 +1,96 @@
"""Upload a test HTML report with multiple links to verify the iframe link fix."""
import requests
API_BASE = "http://www.1415243231.top:30081/api"
PROJECT_ID = 4 # "产品设计周报" - new test project
# Test HTML with various link types
html_content = """<!DOCTYPE html>
<html lang="zh-CN">
<head>
<meta charset="UTF-8">
<title>链接跳转测试报告</title>
<style>
body { font-family: -apple-system, system-ui, sans-serif; max-width: 800px; margin: 40px auto; padding: 20px; line-height: 1.6; color: #1a1a1a; }
h1 { color: #FF7A45; border-bottom: 3px solid #FF7A45; padding-bottom: 8px; }
h2 { color: #1a1a1a; margin-top: 32px; }
.test-box { background: #FFF7E6; border-left: 4px solid #FF7A45; padding: 12px 16px; margin: 12px 0; border-radius: 8px; }
a { color: #FF7A45; text-decoration: underline; font-weight: 500; }
a:hover { color: #1a1a1a; }
.info { background: #f0f0f0; padding: 8px 12px; border-radius: 6px; font-size: 14px; color: #555; }
</style>
</head>
<body>
<h1>HTML 链接跳转测试</h1>
<p class="info">
<strong>测试目标:</strong>验证在 iframe 中点击链接,<strong>不需要 Ctrl+点击</strong>,链接应该正常打开。
</p>
<h2>1. 外部链接(应该打开新标签)</h2>
<div class="test-box">
<p><a href="https://www.google.com" target="_blank">Google</a> —— 普通外部链接</p>
<p><a href="https://github.com" target="_blank">GitHub</a> —— 另一个外部链接</p>
<p><a href="https://www.bing.com" target="_self">Bing</a> —— 强制 target=_self(应该走 base 默认行为)</p>
</div>
<h2>2. 不同 target 行为对比</h2>
<div class="test-box">
<p><a href="https://www.baidu.com" target="_blank">→ target="_blank"(新标签)</a></p>
<p><a href="https://www.zhihu.com" target="_self">→ target="_self"iframe 内)</a></p>
<p><a href="https://www.example.com">→ 无 target(继承 base,默认新标签)</a></p>
</div>
<h2>3. 锚点链接(页面内跳转)</h2>
<div class="test-box">
<p><a href="#section-bottom">跳到页面底部</a></p>
<p><a href="#section-middle">跳到中间部分</a></p>
</div>
<h2 id="section-middle">中间部分(锚点目标 1</h2>
<p>这里是页面的中间部分。Lorem ipsum dolor sit amet, consectetur adipiscing elit. Sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.</p>
<p>Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat.</p>
<h2>4. 相对路径链接</h2>
<div class="test-box">
<p><a href="/">→ 根路径</a></p>
<p><a href="./other-page">→ 当前目录</a></p>
<p><a href="../parent">→ 父目录</a></p>
</div>
<h2>5. 邮件链接</h2>
<div class="test-box">
<p><a href="mailto:test@example.com">发送邮件给 test@example.com</a></p>
</div>
<h2 id="section-bottom">页面底部(锚点目标 2</h2>
<p>恭喜你滚动到了底部。所有链接测试完成!</p>
<p><a href="#">↑ 回到顶部</a></p>
</body>
</html"""
# Save to temp file
test_path = r"D:\Idea Project\publish\agent_test\test_link_click.html"
with open(test_path, "w", encoding="utf-8") as f:
f.write(html_content)
# Upload via API
print(f"正在上传测试 HTML 到项目 {PROJECT_ID}...")
with open(test_path, "rb") as f:
files = {"file": ("test_link_click.html", f, "text/html")}
data = {"projectId": PROJECT_ID, "fileType": "HTML"}
r = requests.post(f"{API_BASE}/reports", files=files, data=data, timeout=30)
if r.status_code == 201:
result = r.json()
print(f"\n[OK] 上传成功")
print(f" - Report ID: {result['id']}")
print(f" - File name: {result['fileName']}")
print(f" - File size: {result.get('fileSize', 'N/A')} bytes")
print(f"\n验证步骤:")
print(f" 1. 打开 https://www.1415243231.top/publish_dishboard")
print(f" 2. 进入项目 #{PROJECT_ID} '产品设计周报'")
print(f" 3. 点击左侧 'test_link_click.html'")
print(f" 4. 在右侧预览区,点击任意链接 → 应该直接打开新标签,无需 Ctrl")
else:
print(f"[FAIL] {r.status_code}: {r.text[:500]}")