Update playwright_model.py
Browse files- playwright_model.py +28 -4
playwright_model.py
CHANGED
|
@@ -33,11 +33,9 @@ async def capture_workflows(public_url: str, pdf_filename: str = "workflow_scree
|
|
| 33 |
if(s && !seen.has(s)){seen.add(s);window.__ordered.push({menu:m,screen:s});}
|
| 34 |
}
|
| 35 |
for(const s of screens) if(!seen.has(s)) window.__ordered.push({menu:null,screen:s});
|
| 36 |
-
|
| 37 |
window.__visitedWorkflows=[];
|
| 38 |
window.__currentIndex=0;
|
| 39 |
window.__done=false;
|
| 40 |
-
|
| 41 |
window.__captureNext=async function(){
|
| 42 |
if(window.__done) return false;
|
| 43 |
if(window.__currentIndex>=window.__ordered.length){window.__done=true;return false;}
|
|
@@ -68,9 +66,35 @@ async def capture_workflows(public_url: str, pdf_filename: str = "workflow_scree
|
|
| 68 |
result = await page.evaluate("window.__captureNext()")
|
| 69 |
if not result:
|
| 70 |
break
|
|
|
|
| 71 |
screen_name = result.get("screenName", f"screen_{index}")
|
| 72 |
-
|
| 73 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 74 |
|
| 75 |
await asyncio.sleep(1.2) # wait for animations/UI updates
|
| 76 |
await page.screenshot(path=screenshot_path, full_page=True)
|
|
|
|
| 33 |
if(s && !seen.has(s)){seen.add(s);window.__ordered.push({menu:m,screen:s});}
|
| 34 |
}
|
| 35 |
for(const s of screens) if(!seen.has(s)) window.__ordered.push({menu:null,screen:s});
|
|
|
|
| 36 |
window.__visitedWorkflows=[];
|
| 37 |
window.__currentIndex=0;
|
| 38 |
window.__done=false;
|
|
|
|
| 39 |
window.__captureNext=async function(){
|
| 40 |
if(window.__done) return false;
|
| 41 |
if(window.__currentIndex>=window.__ordered.length){window.__done=true;return false;}
|
|
|
|
| 66 |
result = await page.evaluate("window.__captureNext()")
|
| 67 |
if not result:
|
| 68 |
break
|
| 69 |
+
|
| 70 |
screen_name = result.get("screenName", f"screen_{index}")
|
| 71 |
+
|
| 72 |
+
# 🧠 Dynamically detect readable title name
|
| 73 |
+
readable_name = await page.evaluate(
|
| 74 |
+
"""(defaultName) => {
|
| 75 |
+
let title = null;
|
| 76 |
+
const activeMenu = document.querySelector('.menu-item.active');
|
| 77 |
+
const visibleTitle = document.querySelector('.page-title, .header-title, main h2');
|
| 78 |
+
if (activeMenu && activeMenu.textContent.trim()) title = activeMenu.textContent.trim();
|
| 79 |
+
else if (visibleTitle && visibleTitle.textContent.trim()) title = visibleTitle.textContent.trim();
|
| 80 |
+
else title = defaultName;
|
| 81 |
+
return title;
|
| 82 |
+
}""",
|
| 83 |
+
screen_name
|
| 84 |
+
)
|
| 85 |
+
|
| 86 |
+
# 🪄 Update visible + browser tab title dynamically
|
| 87 |
+
await page.evaluate(
|
| 88 |
+
"""(titleName) => {
|
| 89 |
+
const titleEl = document.querySelector('.page-title, .header-title, main h2');
|
| 90 |
+
if (titleEl) titleEl.textContent = titleName;
|
| 91 |
+
document.title = titleName;
|
| 92 |
+
}""",
|
| 93 |
+
readable_name
|
| 94 |
+
)
|
| 95 |
+
|
| 96 |
+
screenshot_path = os.path.join(OUTPUT_DIR, f"{readable_name}.png")
|
| 97 |
+
print(f"📸 Capturing {readable_name} -> {screenshot_path}")
|
| 98 |
|
| 99 |
await asyncio.sleep(1.2) # wait for animations/UI updates
|
| 100 |
await page.screenshot(path=screenshot_path, full_page=True)
|