1er
This commit is contained in:
23
backend/app/scraper/browser.py
Normal file
23
backend/app/scraper/browser.py
Normal file
@@ -0,0 +1,23 @@
|
||||
from __future__ import annotations
|
||||
|
||||
from pathlib import Path
|
||||
|
||||
from playwright.async_api import async_playwright, Browser, BrowserContext
|
||||
|
||||
|
||||
async def build_browser_context(headless: bool, viewport: dict[str, int], locale: str, timezone: str) -> BrowserContext:
|
||||
playwright = await async_playwright().start()
|
||||
browser: Browser = await playwright.chromium.launch(headless=headless)
|
||||
context = await browser.new_context(
|
||||
viewport=viewport,
|
||||
locale=locale,
|
||||
timezone_id=timezone,
|
||||
)
|
||||
context.set_default_timeout(30000)
|
||||
return context
|
||||
|
||||
|
||||
async def close_context(context: BrowserContext) -> None:
|
||||
await context.close()
|
||||
await context.browser.close()
|
||||
await context._playwright.stop()
|
||||
Reference in New Issue
Block a user