support new tab magic link logic (#3797)

This commit is contained in:
LawyZheng
2025-10-23 14:38:03 +08:00
committed by GitHub
parent b8525ff703
commit 87625d4c0f
10 changed files with 74 additions and 4 deletions

View File

@@ -3,7 +3,7 @@ from dataclasses import dataclass, field
from typing import Any
from zoneinfo import ZoneInfo
from playwright.async_api import Frame
from playwright.async_api import Frame, Page
@dataclass
@@ -46,6 +46,15 @@ class SkyvernContext:
script_run_parameters: dict[str, Any] = field(default_factory=dict)
script_mode: bool = False
ai_mode_override: str | None = None
# magic link handling
# task_id is the key, page is the value
# we only consider the page is a magic link page in the same task scope
# for example, login block has a magic link page,
# but it will only be considered as a magic link page in the login block scope
# next blocks won't consider the page as a magic link page
magic_link_pages: dict[str, Page] = field(default_factory=dict)
"""
Example output value:
{"loop_value": "str", "output_parameter": "the key of the parameter", "output_value": Any}
@@ -62,6 +71,19 @@ class SkyvernContext:
if task_id in self.totp_codes:
self.totp_codes.pop(task_id)
def add_magic_link_page(self, task_id: str, page: Page) -> None:
self.magic_link_pages[task_id] = page
def has_magic_link_page(self, task_id: str) -> bool:
if task_id not in self.magic_link_pages:
return False
page = self.magic_link_pages[task_id]
if page.is_closed():
self.magic_link_pages.pop(task_id)
return False
return True
_context: ContextVar[SkyvernContext | None] = ContextVar(
"Global context",