add resulting url
Build and Push Docker Images / build-and-push (push) Successful in 1m24s

This commit is contained in:
2026-04-29 15:47:10 +02:00
parent 6ada34a8c8
commit a93bca3c73
25 changed files with 21 additions and 4 deletions
+2
View File
@@ -0,0 +1,2 @@
*.pyc
__pycache__/
+9 -3
View File
@@ -44,9 +44,9 @@ class Viewport(BaseModel):
class InteractionsRequest(BaseModel): class InteractionsRequest(BaseModel):
url: str = Field(..., description="Target URL (will be URL-decoded server-side).") url: str = Field(..., description="Target URL (will be URL-decoded server-side).")
returnType: Optional[Literal["screenshot", "html"]] = Field( returnType: Optional[Literal["screenshot", "html", "resulting_url"]] = Field(
"screenshot", "screenshot",
description="Return a PNG screenshot or HTML content.", description="Return a PNG screenshot, HTML content, or the resulting URL after interactions.",
) )
viewport: Optional[Viewport] = None viewport: Optional[Viewport] = None
scrollX: Optional[int] = None scrollX: Optional[int] = None
@@ -124,7 +124,8 @@ async def screenshot_url(url: str, fullPage: bool = True, x_api_key: Optional[st
description=( description=(
"Run a sequence of interactions (click/type) on a page.\n\n" "Run a sequence of interactions (click/type) on a page.\n\n"
"- `returnType=screenshot` returns `image/png`\n" "- `returnType=screenshot` returns `image/png`\n"
"- `returnType=html` returns `text/html`" "- `returnType=html` returns `text/html`\n"
"- `returnType=resulting_url` returns `application/json` with the final URL"
), ),
responses={ responses={
200: { 200: {
@@ -158,6 +159,11 @@ async def run_interactions(payload: InteractionsRequest, x_api_key: Optional[str
if isinstance(result, dict) and result.get("status") == "error": if isinstance(result, dict) and result.get("status") == "error":
raise HTTPException(status_code=500, detail=result.get("error", "Interaction failed")) raise HTTPException(status_code=500, detail=result.get("error", "Interaction failed"))
if return_type == "resulting_url":
if not isinstance(result, dict):
raise HTTPException(status_code=500, detail="Unexpected resulting_url response")
return result
if return_type == "html": if return_type == "html":
if not isinstance(result, str): if not isinstance(result, str):
raise HTTPException(status_code=500, detail="Unexpected HTML response") raise HTTPException(status_code=500, detail="Unexpected HTML response")
+10 -1
View File
@@ -183,7 +183,7 @@ async def interactions_service(
scroll_x: int | None = None, scroll_x: int | None = None,
scroll_y: int | None = None, scroll_y: int | None = None,
): ):
"""Open `decoded_url`, execute click/type interactions in order, then return screenshot or HTML.""" """Open `decoded_url`, execute click/type interactions in order, then return screenshot, HTML, or resulting_url."""
print(f"Running interactions on {decoded_url} (return_type={return_type})") print(f"Running interactions on {decoded_url} (return_type={return_type})")
async def interactions_operation(page): async def interactions_operation(page):
@@ -392,6 +392,15 @@ async def interactions_service(
except Exception: except Exception:
pass pass
if return_type == "resulting_url":
final_url = unquote(page.url or "")
return {
"status": "success",
"original_url": decoded_url,
"resulting_url": final_url,
"redirected": final_url != decoded_url,
}
if return_type == "html": if return_type == "html":
return await page.content() return await page.content()