Skip to content

Supercharge your AI agents with data from the web and beyond. Building the library for superintelligence. 🔥

Merge pull request #170 from qyou/fix-hardcode-timeout

Nicolase166c07690e4
diff --cc apps/playwright-service/main.py
index 337d2835d,8344adc7b..9cb0c4e57
--- a/apps/playwright-service/main.py
+++ b/apps/playwright-service/main.py
@@@ -34,22 -28,17 +34,28 @@@ async def shutdown_event()
@app.post("/html")
async def root(body: UrlModel):
- context = await browser.new_context()
+ context = None
+ if PROXY_SERVER and PROXY_USERNAME and PROXY_PASSWORD:
+ context = await browser.new_context(proxy={"server": PROXY_SERVER,
+ "username": PROXY_USERNAME,
+ "password": PROXY_PASSWORD})
+ else:
+ context = await browser.new_context()
+
+ if BLOCK_MEDIA:
+ await context.route("**/*.{png,jpg,jpeg,gif,svg,mp3,mp4,avi,flac,ogg,wav,webm}",
+ handler=lambda route, request: route.abort())
+
page = await context.new_page()
- await page.goto(body.url, timeout=15000) # Set max timeout to 15s
- if body.wait: # Check if wait parameter is provided in the request body
- await page.wait_for_timeout(body.wait) # Convert seconds to milliseconds for playwright
+ await page.goto(
+ body.url,
+ wait_until="load",
+ timeout=body.timeout if body.timeout else 15000,
+ )
+ # Wait != timeout. Wait is the time to wait after the page is loaded - useful in some cases were "load" / "networkidle" is not enough
+ if body.wait:
+ await page.wait_for_timeout(body.wait)
+
page_content = await page.content()
await context.close()
json_compatible_item_data = {"content": page_content}