common: delete stale file

This commit is contained in:
Corentin Sechet 2022-04-11 16:40:15 +02:00
parent 134828ea87
commit ae0024f343
1 changed files with 0 additions and 23 deletions

View File

@ -1,23 +0,0 @@
"""Playwright encapsulation & helpers"""
from contextlib import asynccontextmanager
from typing import AsyncGenerator
from playwright.async_api import BrowserContext, Route, async_playwright
from frontools.sources import Source
@asynccontextmanager
async def get_cached_browser(source: Source) -> AsyncGenerator[BrowserContext, None]:
"""Return a Playwright browser that will eventually get files from local cache"""
async def _cache_route(route: Route) -> None:
content = await source.get_url(route.request.url)
await route.fulfill(body=content)
async with async_playwright() as pwright:
browser = await pwright.firefox.launch()
context = await browser.new_context()
await context.route("*", _cache_route)
yield context
await browser.close()