The max_steps cap in scroll_to_bottom is a good detail. Infinite-scroll pages are where most homemade full-page scripts hang.
There's one gap left after scrolling. A lazy image can have started loading but not finished decoding by the time you scroll back to the top and capture, so you still get the occasional grey box. Waiting for the images to actually finish closes most of that:
scroll_to_bottom(page)
page.wait_for_function(
"Array.from(document.images).every(img => img.complete && img.naturalWidth > 0)",
timeout=10000,
)
page.screenshot(path=output, full_page=True)
(Wrap it in the same PlaywrightTimeout try/except you already use for networkidle, because one broken image URL shouldn't fail the whole capture.) Cookie banners are the other common problem in full-page shots. page.add_style_tag() with a few known banner selectors set to display:none is the cheap fix.
For the "hundreds on a schedule" case from your intro, running Chromium yourself becomes most of the work: memory, timeouts, retries, and keeping the browser build up to date. At that point a hosted endpoint with the same options may be simpler. The APIFreaks Website Screenshot API maps closely to the flags in your webshot.py:
import requests
r = requests.get(
"api.apifreaks.com/v1.0/screenshot",
params={
"url": "example.com",
"full_page": "true",
"lazy_load": "true", # does the scroll-through for you
"scroll_delay": 150, # same idea as your pause_ms
"no_cookie_banners": "true",
"dark_mode": "true",
"retina": "true",
"file_type": "PNG",
"output": "json",
},
headers={"X-apiKey": API_KEY},
timeout=120,
)
print(r.json()["screenshot"]) # hosted file URL
A basic capture costs 50 credits and new accounts start with 10,000, so you can test a batch before deciding whether to keep running Playwright yourself.