Merge pull request #192 from openqj/feat-chromium-flags-quality

perf: Chromium 启动 flag 微调 + screencast 画质 q60→q50
This commit is contained in:
openqj authored and GitHub committed 2026-10-30 14:34:56 +08:00
commit b3f4597d3f
2 files changed
+29 -5

No files matched your search

+22 -3
View File
@@ -83,9 +83,23 @@ class Browser:
else:
from playwright.sync_api import sync_playwright
pw = sync_playwright().start()
# Extra flags skip first-run/setup work only; they
# change nothing about page rendering or tool
# behaviour. Measured 2026-10-30 (runsc container,
# launch + new_page, 3 runs each, alternating):
# old median 0.889s, new median 0.819s -- ~70ms,
# inside run-to-run noise (0.70-0.99s either way).
# Kept anyway: zero cost, directionally faster.
launch = {"args": ["--no-sandbox",
"--disable-dev-shm-usage",
"--disable-gpu"]}
"--disable-gpu",
"--no-first-run",
"--no-default-browser-check",
"--disable-default-apps",
"--disable-extensions",
"--disable-background-networking",
"--disable-sync",
"--disable-translate"]}
if self.proxy:
launch["proxy"] = {"server": self.proxy}
browser = pw.chromium.launch(**launch)
@@ -318,8 +332,13 @@ class Browser:
# bytes), so dropping the frame-skip buys
# responsiveness exactly when it matters -- scrolling,
# dragging, animation -- without a static-page tax.
# quality 50 (was 60): measured 2026-10-30 on a
# text+gradient page, 62068 -> 56428 bytes (-9%).
# Less than the 30% rule of thumb, but free: same
# 1280x800 pixels, so click coordinates are
# unaffected. Revert to 60 if text looks soft.
cdp.send("Page.startScreencast",
{"format": "jpeg", "quality": 60,
{"format": "jpeg", "quality": 50,
"maxWidth": 1280, "maxHeight": 800,
"everyNthFrame": 1})
self._cdp = cdp
@@ -343,7 +362,7 @@ class Browser:
try:
result = self._cdp.send(
"Page.captureScreenshot",
{"format": "jpeg", "quality": 60})
{"format": "jpeg", "quality": 50})
data = result.get("data") if isinstance(result, dict) \
else None
if data:
+7 -2
View File
@@ -180,6 +180,11 @@ class BrowserTest(unittest.TestCase):
{"server": "http://proxy:8888"})
self.assertIn("--no-sandbox",
self.browser._pw.launch_kwargs["args"])
for flag in ("--no-first-run", "--no-default-browser-check",
"--disable-default-apps", "--disable-extensions",
"--disable-background-networking", "--disable-sync",
"--disable-translate"):
self.assertIn(flag, self.browser._pw.launch_kwargs["args"])
def test_snapshot_truncates_with_flag(self):
self.browser.navigate("https://example.com")
@@ -254,7 +259,7 @@ class BrowserTest(unittest.TestCase):
self.browser.set_frame_sink(sink)
self.browser.navigate("https://example.com")
self.assertIn(("Page.startScreencast",
{"format": "jpeg", "quality": 60,
{"format": "jpeg", "quality": 50,
"maxWidth": 1280, "maxHeight": 800,
"everyNthFrame": 1}),
[(m, p) for m, p in self.page.cdp.sent])
@@ -272,7 +277,7 @@ class BrowserTest(unittest.TestCase):
result = self.browser.navigate("https://example.com")
self.assertTrue(result["ok"])
self.assertIn(("Page.captureScreenshot",
{"format": "jpeg", "quality": 60}),
{"format": "jpeg", "quality": 50}),
[(m, p) for m, p in self.page.cdp.sent])
frame = self.browser.pump_screencast()
self.assertEqual(frame, "EAGERDATA")