69 lines
2.3 KiB
Python
69 lines
2.3 KiB
Python
from playwright.sync_api import sync_playwright
|
|
|
|
URLS = [
|
|
("Home", "http://192.168.5.9:5173/"),
|
|
("Utility", "http://192.168.5.9:5173/utility"),
|
|
("Settings", "http://192.168.5.9:5173/settings"),
|
|
("Register", "http://192.168.5.9:5173/register"),
|
|
("Chat", "http://192.168.5.9:5173/chat"),
|
|
("Articles", "http://192.168.5.9:5173/articles"),
|
|
]
|
|
|
|
JS_OVERFLOW = """() => {
|
|
return {
|
|
vw: window.innerWidth,
|
|
vh: window.innerHeight,
|
|
bSW: document.body.scrollWidth,
|
|
bCW: document.body.clientWidth,
|
|
hSW: document.documentElement.scrollWidth,
|
|
hCW: document.documentElement.clientWidth,
|
|
hO: document.body.scrollWidth > document.body.clientWidth + 1
|
|
};
|
|
}"""
|
|
|
|
JS_WIDE = """() => {
|
|
const vw = window.innerWidth;
|
|
return Array.from(document.querySelectorAll('*'))
|
|
.filter(el => {
|
|
const r = el.getBoundingClientRect();
|
|
return r.width > vw + 10 && el.tagName !== 'HTML' && el.tagName !== 'BODY';
|
|
})
|
|
.slice(0, 10)
|
|
.map(el => ({
|
|
tag: el.tagName,
|
|
cls: (el.className || '').toString().substring(0, 60),
|
|
w: Math.round(el.getBoundingClientRect().width),
|
|
x: Math.round(el.getBoundingClientRect().x),
|
|
}));
|
|
}"""
|
|
|
|
def audit(page, name, url):
|
|
page.goto(url, wait_until="networkidle", timeout=15000)
|
|
page.wait_for_timeout(2000)
|
|
safe = name.replace(" ", "_").lower()
|
|
page.screenshot(path=f"C:/Users/12914/Desktop/vscode/mobile_audit_{safe}.png")
|
|
data = page.evaluate(JS_OVERFLOW)
|
|
large = page.evaluate(JS_WIDE)
|
|
flag = "X" if data["hO"] else "OK"
|
|
print(f"=== {name} [{flag}] === vw={data['vw']}x{data['vh']} body={data['bSW']}x{data['bCW']} html={data['hSW']}x{data['hCW']}")
|
|
for l in large:
|
|
print(f" WIDER: <{l['tag']}> .{l['cls'][:40]} w={l['w']} x={l['x']}")
|
|
if not large:
|
|
print(" No oversized elements")
|
|
return data
|
|
|
|
with sync_playwright() as p:
|
|
browser = p.chromium.launch()
|
|
ctx = browser.new_context(
|
|
viewport={"width": 390, "height": 844},
|
|
device_scale_factor=3,
|
|
user_agent="Mozilla/5.0 (iPhone; CPU iPhone OS 16_0 like Mac OS X)",
|
|
)
|
|
page = ctx.new_page()
|
|
for name, url in URLS:
|
|
try:
|
|
audit(page, name, url)
|
|
except Exception as e:
|
|
print(f" ERROR: {e}")
|
|
browser.close()
|