dina1 commited on
Commit
d15185e
·
verified ·
1 Parent(s): 72d5410

Update playwright_model.py

Browse files
Files changed (1) hide show
  1. playwright_model.py +24 -23
playwright_model.py CHANGED
@@ -16,7 +16,7 @@ async def capture_workflows(public_url: str, pdf_filename: str = "workflow_scree
16
  print(f"Opening page: {public_url}")
17
  await page.goto(public_url, wait_until="load")
18
 
19
- # Wait until layout stabilizes
20
  async def wait_for_layout_stable():
21
  await page.evaluate("""
22
  (async () => {
@@ -40,55 +40,54 @@ async def capture_workflows(public_url: str, pdf_filename: str = "workflow_scree
40
  })();
41
  """)
42
 
43
- # Sidebar fixed; top bar remains dynamic
44
- async def fix_sidebar_only():
45
  try:
46
  await page.evaluate("""
47
- // Unfix all headers / topbars
48
- document.querySelectorAll('header, .topbar, .top-bar, .header, .navbar').forEach(el => {
49
- el.style.position = 'relative';
50
- el.style.top = 'auto';
51
- el.style.zIndex = 'auto';
52
- });
53
-
54
- // Fix only sidebar
55
  const sidebar = document.querySelector('aside, .sidebar, nav');
 
 
 
 
 
 
 
 
56
  if (sidebar) {
57
  const rect = sidebar.getBoundingClientRect();
58
  const sidebarWidth = rect.width || sidebar.offsetWidth || 220;
59
  sidebar.style.position = 'fixed';
60
- sidebar.style.top = '0';
61
  sidebar.style.left = '0';
62
- sidebar.style.height = '100vh';
63
  sidebar.style.width = sidebarWidth + 'px';
64
- sidebar.style.zIndex = '999';
65
- sidebar.style.overflowY = 'auto';
66
  sidebar.style.transition = 'none';
67
  sidebar.dataset.locked = 'true';
68
  }
69
 
70
- // Shift main content right to avoid overlap
71
  const main = document.querySelector('main, .main-content, .app-body, .content');
72
  if (main && sidebar) {
73
  main.style.marginLeft = sidebar.offsetWidth + 'px';
74
  main.style.position = 'relative';
75
  }
76
 
77
- // Reset scrolling and page margins
78
  document.body.style.margin = '0';
79
  document.body.style.padding = '0';
80
  document.body.style.overflowX = 'hidden';
81
- window.scrollTo(0, 0);
82
  """)
83
  except Exception as e:
84
  print(f"[WARN] Sidebar fix failed: {e}")
85
 
 
86
  await page.wait_for_selector("aside, .sidebar, nav", timeout=5000)
87
  await wait_for_layout_stable()
88
- await fix_sidebar_only()
89
  await asyncio.sleep(1)
90
 
91
- # JS navigation logic
92
  js_logic = """
93
  (function(){
94
  const menus=[...document.querySelectorAll('.menu-item')];
@@ -164,7 +163,7 @@ async def capture_workflows(public_url: str, pdf_filename: str = "workflow_scree
164
  screenshots = []
165
  index = 0
166
 
167
- # Loop through screens
168
  while True:
169
  result = await page.evaluate("window.__captureNext()")
170
  if not result:
@@ -176,11 +175,12 @@ async def capture_workflows(public_url: str, pdf_filename: str = "workflow_scree
176
  print(f"📸 Capturing main screen: {screen_name}")
177
 
178
  await wait_for_layout_stable()
179
- await fix_sidebar_only()
180
  await asyncio.sleep(1.0)
181
  await page.screenshot(path=screenshot_path, full_page=True)
182
  screenshots.append(screenshot_path)
183
 
 
184
  first_active_skipped = False
185
  for sub in sub_screens:
186
  is_active = await page.evaluate(
@@ -200,7 +200,7 @@ async def capture_workflows(public_url: str, pdf_filename: str = "workflow_scree
200
  print(f" ↳ Capturing sub-screen: {sub}")
201
  await page.evaluate(f"window.__clickSubScreen('{sub}')")
202
  await wait_for_layout_stable()
203
- await fix_sidebar_only()
204
  await asyncio.sleep(1.0)
205
 
206
  sub_name_clean = sub.replace(" ", "_").lower()
@@ -212,6 +212,7 @@ async def capture_workflows(public_url: str, pdf_filename: str = "workflow_scree
212
 
213
  await browser.close()
214
 
 
215
  if not screenshots:
216
  raise RuntimeError("No screenshots captured — check if .screen elements exist!")
217
 
 
16
  print(f"Opening page: {public_url}")
17
  await page.goto(public_url, wait_until="load")
18
 
19
+ # --- Utility: wait for stable layout ---
20
  async def wait_for_layout_stable():
21
  await page.evaluate("""
22
  (async () => {
 
40
  })();
41
  """)
42
 
43
+ # --- Auto-detect top bar and fix sidebar below it ---
44
+ async def fix_sidebar_permanently():
45
  try:
46
  await page.evaluate("""
 
 
 
 
 
 
 
 
47
  const sidebar = document.querySelector('aside, .sidebar, nav');
48
+ const topbar = document.querySelector('.topbar, header, .header, .app-header, .navbar, .page-header');
49
+
50
+ let topOffset = 0;
51
+ if (topbar) {
52
+ const rect = topbar.getBoundingClientRect();
53
+ topOffset = rect.bottom || rect.height || 60;
54
+ }
55
+
56
  if (sidebar) {
57
  const rect = sidebar.getBoundingClientRect();
58
  const sidebarWidth = rect.width || sidebar.offsetWidth || 220;
59
  sidebar.style.position = 'fixed';
60
+ sidebar.style.top = topOffset + 'px';
61
  sidebar.style.left = '0';
62
+ sidebar.style.height = `calc(100vh - ${topOffset}px)`;
63
  sidebar.style.width = sidebarWidth + 'px';
64
+ sidebar.style.zIndex = '1000';
65
+ sidebar.style.overflow = 'hidden';
66
  sidebar.style.transition = 'none';
67
  sidebar.dataset.locked = 'true';
68
  }
69
 
 
70
  const main = document.querySelector('main, .main-content, .app-body, .content');
71
  if (main && sidebar) {
72
  main.style.marginLeft = sidebar.offsetWidth + 'px';
73
  main.style.position = 'relative';
74
  }
75
 
76
+ window.scrollTo(0, 0);
77
  document.body.style.margin = '0';
78
  document.body.style.padding = '0';
79
  document.body.style.overflowX = 'hidden';
 
80
  """)
81
  except Exception as e:
82
  print(f"[WARN] Sidebar fix failed: {e}")
83
 
84
+ # --- Wait until sidebar exists ---
85
  await page.wait_for_selector("aside, .sidebar, nav", timeout=5000)
86
  await wait_for_layout_stable()
87
+ await fix_sidebar_permanently()
88
  await asyncio.sleep(1)
89
 
90
+ # --- JS Logic: detect workflows and tabs dynamically ---
91
  js_logic = """
92
  (function(){
93
  const menus=[...document.querySelectorAll('.menu-item')];
 
163
  screenshots = []
164
  index = 0
165
 
166
+ # --- Capture all screens ---
167
  while True:
168
  result = await page.evaluate("window.__captureNext()")
169
  if not result:
 
175
  print(f"📸 Capturing main screen: {screen_name}")
176
 
177
  await wait_for_layout_stable()
178
+ await fix_sidebar_permanently()
179
  await asyncio.sleep(1.0)
180
  await page.screenshot(path=screenshot_path, full_page=True)
181
  screenshots.append(screenshot_path)
182
 
183
+ # --- Sub-tabs ---
184
  first_active_skipped = False
185
  for sub in sub_screens:
186
  is_active = await page.evaluate(
 
200
  print(f" ↳ Capturing sub-screen: {sub}")
201
  await page.evaluate(f"window.__clickSubScreen('{sub}')")
202
  await wait_for_layout_stable()
203
+ await fix_sidebar_permanently()
204
  await asyncio.sleep(1.0)
205
 
206
  sub_name_clean = sub.replace(" ", "_").lower()
 
212
 
213
  await browser.close()
214
 
215
+ # --- Generate PDF ---
216
  if not screenshots:
217
  raise RuntimeError("No screenshots captured — check if .screen elements exist!")
218