Replies: 1 comment
-
It seems there are a few issues with the pdf handling in chromium headless: https://bugs.chromium.org/p/chromium/issues/detail?id=761295 Now, let's get in the fun parts. When we pass a URL that points to a file (exe, pdf, ...) to
Which makes sense because we're not loading an HTML page or anything the browser can render. so we need to catch that and handle it appropriately. The code below works as a standalone sample, and I'm not sure if it is intended by the playwright devs: #!/usr/bin/env python3
import asyncio
from playwright.async_api import async_playwright
from playwright.async_api import Error, TimeoutError as PlaywrightTimeoutError
async def main() -> None:
async with async_playwright() as p:
browser = await p.chromium.launch()
context = await browser.new_context()
# Open new page
page = await context.new_page()
# Go to the file to download
try:
# await page.goto("https://www.google.fr")
await page.goto("https://the.earth.li/~sgtatham/putty/0.77/w64/putty.exe")
# await page.goto("dfjdskfdsjgjhdsf")
except Error as e:
print(e)
# page.goto failed, but it (might have) triggered a download event.
# If it is the case, let's try to save it.
try:
async with page.expect_download(timeout=5) as download_info:
download = await download_info.value
await download.save_as(download.suggested_filename)
except PlaywrightTimeoutError:
print('nope, no download were triggered')
asyncio.run(main()) |
Beta Was this translation helpful? Give feedback.
-
Right now, if you submit a URL that triggers a download on Lookyloo, you get an error.
The good thing is that playwright supports what we need to handle that (see Lookyloo/PlaywrightCapture#1).
When it is implement on PlaywrightCapture side, we need to handle that in Lookyloo.
Beta Was this translation helpful? Give feedback.
All reactions