-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathverify_assets.py
More file actions
58 lines (47 loc) · 1.83 KB
/
Copy pathverify_assets.py
File metadata and controls
58 lines (47 loc) · 1.83 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
import asyncio
from playwright.async_api import async_playwright
import os
async def verify_page(browser, path):
context = await browser.new_context()
# Abort external requests
await context.route("**/*", lambda route:
route.abort() if not (route.request.url.startswith("http://localhost:8080") or "favicon.ico" in route.request.url)
else route.continue_()
)
page = await context.new_page()
url = f"http://localhost:8080{path}"
try:
# Track requests
requests = []
page.on("request", lambda request: requests.append(request.url))
print(f"Navigating to {url}...")
response = await page.goto(url, wait_until="load", timeout=10000)
if response.status != 200:
print(f" - FAILURE: Received status {response.status} for {path}")
return False
await asyncio.sleep(1) # Wait for any late requests
found_assets = [req_url for req_url in requests if "?v=" in req_url]
print(f"Summary for {path}: SUCCESS")
print(f" - Found {len(found_assets)} versioned assets.")
return True
except Exception as e:
print(f"Error for {path}: {e}")
return False
finally:
await context.close()
async def main():
async with async_playwright() as p:
browser = await p.chromium.launch(headless=True)
try:
paths = ["/", "/links.html", "/profiles.html", "/404.html"]
tasks = [verify_page(browser, path) for path in paths]
results = await asyncio.gather(*tasks)
if all(results):
print("\nAll pages verified successfully.")
else:
print("\nSome pages failed verification.")
exit(1)
finally:
await browser.close()
if __name__ == "__main__":
asyncio.run(main())