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

Update playwright_model.py

Browse files
Files changed (1) hide show
  1. playwright_model.py +26 -18
playwright_model.py CHANGED
@@ -40,29 +40,39 @@ async def capture_workflows(public_url: str, pdf_filename: str = "workflow_scree
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
  }
@@ -70,21 +80,19 @@ async def capture_workflows(public_url: str, pdf_filename: str = "workflow_scree
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 ---
@@ -175,12 +183,12 @@ async def capture_workflows(public_url: str, pdf_filename: str = "workflow_scree
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,7 +208,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_permanently()
204
  await asyncio.sleep(1.0)
205
 
206
  sub_name_clean = sub.replace(" ", "_").lower()
 
40
  })();
41
  """)
42
 
43
+ # --- Fix only sidebar; keep top bar dynamic per screen ---
44
+ async def fix_layout_dynamically():
45
  try:
46
  await page.evaluate("""
47
  const sidebar = document.querySelector('aside, .sidebar, nav');
48
+ const topbar = document.querySelector('.top-bar, header, .app-header, .navbar, .page-header');
49
+
50
+ // Reset old fixed styles
51
+ [sidebar, topbar].forEach(el => {
52
+ if (!el) return;
53
+ el.style.position = '';
54
+ el.style.top = '';
55
+ el.style.left = '';
56
+ el.style.width = '';
57
+ el.style.height = '';
58
+ el.style.zIndex = '';
59
+ el.style.overflow = '';
60
+ el.style.transition = '';
61
+ });
62
 
63
+ // Fix sidebar only (topbar remains dynamic)
64
  if (sidebar) {
65
  const rect = sidebar.getBoundingClientRect();
66
  const sidebarWidth = rect.width || sidebar.offsetWidth || 220;
67
+ const topOffset = topbar ? topbar.offsetHeight || 60 : 60;
68
+
69
  sidebar.style.position = 'fixed';
70
  sidebar.style.top = topOffset + 'px';
71
  sidebar.style.left = '0';
72
  sidebar.style.height = `calc(100vh - ${topOffset}px)`;
73
  sidebar.style.width = sidebarWidth + 'px';
74
  sidebar.style.zIndex = '1000';
75
+ sidebar.style.overflow = 'auto';
76
  sidebar.style.transition = 'none';
77
  sidebar.dataset.locked = 'true';
78
  }
 
80
  const main = document.querySelector('main, .main-content, .app-body, .content');
81
  if (main && sidebar) {
82
  main.style.marginLeft = sidebar.offsetWidth + 'px';
83
+ main.style.marginTop = topbar ? (topbar.offsetHeight || 60) + 'px' : '0';
84
  main.style.position = 'relative';
85
  }
86
 
87
  window.scrollTo(0, 0);
 
 
 
88
  """)
89
  except Exception as e:
90
+ print(f"[WARN] Layout fix failed: {e}")
91
 
92
  # --- Wait until sidebar exists ---
93
  await page.wait_for_selector("aside, .sidebar, nav", timeout=5000)
94
  await wait_for_layout_stable()
95
+ await fix_layout_dynamically()
96
  await asyncio.sleep(1)
97
 
98
  # --- JS Logic: detect workflows and tabs dynamically ---
 
183
  print(f"📸 Capturing main screen: {screen_name}")
184
 
185
  await wait_for_layout_stable()
186
+ await fix_layout_dynamically()
187
  await asyncio.sleep(1.0)
188
  await page.screenshot(path=screenshot_path, full_page=True)
189
  screenshots.append(screenshot_path)
190
 
191
+ # --- Capture sub-tabs ---
192
  first_active_skipped = False
193
  for sub in sub_screens:
194
  is_active = await page.evaluate(
 
208
  print(f" ↳ Capturing sub-screen: {sub}")
209
  await page.evaluate(f"window.__clickSubScreen('{sub}')")
210
  await wait_for_layout_stable()
211
+ await fix_layout_dynamically()
212
  await asyncio.sleep(1.0)
213
 
214
  sub_name_clean = sub.replace(" ", "_").lower()