Merge pull request '[CODER] Create screenshot script for linux.org' (#50) from feature/issue-48 into main

This commit is contained in:
Samuel James 2026-07-23 20:06:14 +00:00
commit 8af6709f3b
2 changed files with 42 additions and 0 deletions

1
requirements.txt Normal file
View File

@ -0,0 +1 @@
playwright>=1.44.0

41
screenshot.py Normal file
View File

@ -0,0 +1,41 @@
import asyncio
from pathlib import Path
from playwright.async_api import async_playwright
OUTPUT_FILE: Path = Path("screenshot.png")
TARGET_URL: str = "https://linux.org"
async def capture_screenshot(url: str, output_path: Path) -> None:
"""Navigate to a URL, wait for the page to load, and save a screenshot.
Args:
url: The URL to navigate to.
output_path: The file path where the screenshot will be saved.
"""
async with async_playwright() as pw:
# Launch Chromium in headless mode
browser = await pw.chromium.launch(headless=True)
page = await browser.new_page(
viewport={"width": 1280, "height": 900}
)
# Navigate and wait until network is idle (page fully loaded)
await page.goto(url, wait_until="networkidle", timeout=30_000)
# Persist screenshot to disk
await page.screenshot(path=str(output_path), full_page=False)
await browser.close()
print(f"Screenshot saved to {output_path.resolve()}")
def main() -> None:
"""Entry point: capture a screenshot of the target URL."""
asyncio.run(capture_screenshot(TARGET_URL, OUTPUT_FILE))
if __name__ == "__main__":
main()