feat: add multi-tab support to remote browser

This commit is contained in:
liumangmang
2026-05-30 09:51:51 +08:00
parent 5c20ddc8e6
commit 3ab3a5e26f
7 changed files with 440 additions and 16 deletions
+13 -8
View File
@@ -159,7 +159,7 @@ def test_screenshot_throttled_save():
try:
from unittest.mock import AsyncMock, MagicMock
from app.services.browser_session_service import BrowserSession
from app.services.browser_session_service import BrowserSession, BrowserTab
# Mock Context & Page
fake_context = AsyncMock()
@@ -172,7 +172,8 @@ def test_screenshot_throttled_save():
custom_page_id=1,
profile_key="page-1-test",
context=fake_context,
page=fake_page,
tabs={"main": BrowserTab(id="main", page=fake_page, created_at=0.0)},
active_tab_id="main",
lock=asyncio.Lock(),
last_saved_state_at=0.0
)
@@ -204,7 +205,8 @@ def test_screenshot_throttled_save():
custom_page_id=0,
profile_key="auth-capture-xyz",
context=fake_context,
page=fake_page,
tabs={"main": BrowserTab(id="main", page=fake_page, created_at=0.0)},
active_tab_id="main",
lock=asyncio.Lock(),
last_saved_state_at=0.0
)
@@ -228,7 +230,7 @@ def test_close_saves_state_and_cleans_up():
try:
from unittest.mock import AsyncMock, MagicMock
from app.services.browser_session_service import BrowserSession
from app.services.browser_session_service import BrowserSession, BrowserTab
fake_context = AsyncMock()
fake_page = MagicMock()
@@ -240,7 +242,8 @@ def test_close_saves_state_and_cleans_up():
custom_page_id=2,
profile_key="page-2-test",
context=fake_context,
page=fake_page,
tabs={"main": BrowserTab(id="main", page=fake_page, created_at=0.0)},
active_tab_id="main",
lock=asyncio.Lock(),
last_saved_state_at=time.monotonic() # 此时在限流内
)
@@ -260,7 +263,8 @@ def test_close_saves_state_and_cleans_up():
custom_page_id=0,
profile_key="auth-capture-abc",
context=eph_context,
page=eph_page,
tabs={"main": BrowserTab(id="main", page=eph_page, created_at=0.0)},
active_tab_id="main",
lock=asyncio.Lock(),
last_saved_state_at=0.0
)
@@ -382,7 +386,7 @@ def test_websocket_event_saves_state():
try:
from unittest.mock import AsyncMock, MagicMock
from app.services.browser_session_service import BrowserSession
from app.services.browser_session_service import BrowserSession, BrowserTab
fake_context = AsyncMock()
fake_page = MagicMock()
@@ -395,7 +399,8 @@ def test_websocket_event_saves_state():
custom_page_id=3,
profile_key="page-3-ws-test",
context=fake_context,
page=fake_page,
tabs={"main": BrowserTab(id="main", page=fake_page, created_at=0.0)},
active_tab_id="main",
lock=asyncio.Lock(),
last_saved_state_at=0.0
)