cmdop 0.1.22__py3-none-any.whl → 0.1.24__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- cmdop/__init__.py +1 -1
- cmdop/_generated/rpc_messages/browser_pb2.py +135 -85
- cmdop/_generated/rpc_messages/browser_pb2.pyi +270 -2
- cmdop/_generated/rpc_messages_pb2.pyi +25 -0
- cmdop/_generated/service_pb2.py +2 -2
- cmdop/_generated/service_pb2_grpc.py +345 -0
- cmdop/helpers/__init__.py +8 -0
- cmdop/helpers/network_analyzer.py +349 -0
- cmdop/services/browser/capabilities/__init__.py +4 -0
- cmdop/services/browser/capabilities/fetch.py +1 -2
- cmdop/services/browser/capabilities/network.py +245 -0
- cmdop/services/browser/capabilities/visual.py +100 -0
- cmdop/services/browser/models.py +103 -0
- cmdop/services/browser/service/sync.py +204 -4
- cmdop/services/browser/session.py +42 -4
- cmdop-0.1.24.dist-info/METADATA +322 -0
- {cmdop-0.1.22.dist-info → cmdop-0.1.24.dist-info}/RECORD +19 -16
- cmdop-0.1.22.dist-info/METADATA +0 -291
- {cmdop-0.1.22.dist-info → cmdop-0.1.24.dist-info}/WHEEL +0 -0
- {cmdop-0.1.22.dist-info → cmdop-0.1.24.dist-info}/licenses/LICENSE +0 -0
|
@@ -0,0 +1,100 @@
|
|
|
1
|
+
"""Visual capability - CMDOP plugin overlay effects."""
|
|
2
|
+
|
|
3
|
+
from __future__ import annotations
|
|
4
|
+
|
|
5
|
+
import time
|
|
6
|
+
|
|
7
|
+
from ._base import BaseCapability
|
|
8
|
+
|
|
9
|
+
|
|
10
|
+
class VisualCapability(BaseCapability):
|
|
11
|
+
"""Visual effects via CMDOP browser plugin.
|
|
12
|
+
|
|
13
|
+
Provides toast notifications, click effects, highlights, etc.
|
|
14
|
+
|
|
15
|
+
Usage:
|
|
16
|
+
b.visual.toast("Hello!")
|
|
17
|
+
b.visual.countdown(10) # Smart countdown with early exit
|
|
18
|
+
b.visual.highlight(".button")
|
|
19
|
+
"""
|
|
20
|
+
|
|
21
|
+
def _dispatch(self, action: str, data: dict) -> None:
|
|
22
|
+
"""Dispatch visual action via CMDOP Visual extension.
|
|
23
|
+
|
|
24
|
+
Uses "mw:" prefix for main world execution to access __CMDOP_VISUAL__.
|
|
25
|
+
The extension API internally handles postMessage to content script.
|
|
26
|
+
"""
|
|
27
|
+
import json
|
|
28
|
+
data_json = json.dumps(data)
|
|
29
|
+
# "mw:" prefix tells Go backend to execute in main world context
|
|
30
|
+
self._js(f"""mw:(() => {{
|
|
31
|
+
const data = {data_json};
|
|
32
|
+
const api = window.__CMDOP_VISUAL__;
|
|
33
|
+
if (!api) return;
|
|
34
|
+
|
|
35
|
+
switch ('{action}') {{
|
|
36
|
+
case 'toast': api.showToast?.(data.message); break;
|
|
37
|
+
case 'clearToasts': api.clearToasts?.(); break;
|
|
38
|
+
case 'click': api.showClick?.(data.x, data.y, data.type || 'left'); break;
|
|
39
|
+
case 'move': api.showMouseMove?.(data.fromX, data.fromY, data.toX, data.toY); break;
|
|
40
|
+
case 'highlight': api.showHighlight?.(data.selector); break;
|
|
41
|
+
case 'hideHighlight': api.hideHighlight?.(); break;
|
|
42
|
+
case 'clearTrail': api.clearTrail?.(); break;
|
|
43
|
+
case 'state': api.setAutomationState?.(data.state); break;
|
|
44
|
+
}}
|
|
45
|
+
}})()
|
|
46
|
+
""")
|
|
47
|
+
|
|
48
|
+
def toast(self, message: str) -> None:
|
|
49
|
+
"""Show toast notification in browser."""
|
|
50
|
+
self._dispatch("toast", {"message": message})
|
|
51
|
+
|
|
52
|
+
def clear_toasts(self) -> None:
|
|
53
|
+
"""Clear all toast notifications."""
|
|
54
|
+
self._dispatch("clearToasts", {})
|
|
55
|
+
|
|
56
|
+
def click(self, x: int, y: int, click_type: str = "left") -> None:
|
|
57
|
+
"""Show click effect at coordinates."""
|
|
58
|
+
self._dispatch("click", {"x": x, "y": y, "type": click_type})
|
|
59
|
+
|
|
60
|
+
def move(self, from_x: int, from_y: int, to_x: int, to_y: int) -> None:
|
|
61
|
+
"""Show mouse movement trail."""
|
|
62
|
+
self._dispatch("move", {"fromX": from_x, "fromY": from_y, "toX": to_x, "toY": to_y})
|
|
63
|
+
|
|
64
|
+
def highlight(self, selector: str) -> None:
|
|
65
|
+
"""Highlight element by selector."""
|
|
66
|
+
self._dispatch("highlight", {"selector": selector})
|
|
67
|
+
|
|
68
|
+
def hide_highlight(self) -> None:
|
|
69
|
+
"""Hide element highlight."""
|
|
70
|
+
self._dispatch("hideHighlight", {})
|
|
71
|
+
|
|
72
|
+
def clear_trail(self) -> None:
|
|
73
|
+
"""Clear cursor trail."""
|
|
74
|
+
self._dispatch("clearTrail", {})
|
|
75
|
+
|
|
76
|
+
def set_state(self, state: str) -> None:
|
|
77
|
+
"""Set automation state: 'idle', 'active', 'busy'."""
|
|
78
|
+
self._dispatch("state", {"state": state})
|
|
79
|
+
|
|
80
|
+
def countdown(self, seconds: int, message: str = "Click pagination!") -> None:
|
|
81
|
+
"""Visual countdown timer with toast notifications.
|
|
82
|
+
|
|
83
|
+
Shows countdown in browser while user interacts with page.
|
|
84
|
+
No early exit - just waits the full duration.
|
|
85
|
+
|
|
86
|
+
Args:
|
|
87
|
+
seconds: Seconds to wait
|
|
88
|
+
message: Message to show with countdown
|
|
89
|
+
"""
|
|
90
|
+
for i in range(seconds, 0, -1):
|
|
91
|
+
try:
|
|
92
|
+
self.clear_toasts()
|
|
93
|
+
self.toast(f"⏱️ {i}s - {message}")
|
|
94
|
+
except Exception:
|
|
95
|
+
pass
|
|
96
|
+
|
|
97
|
+
print(f"{i}", end=" ", flush=True)
|
|
98
|
+
time.sleep(1)
|
|
99
|
+
|
|
100
|
+
print("done")
|
cmdop/services/browser/models.py
CHANGED
|
@@ -2,6 +2,7 @@
|
|
|
2
2
|
|
|
3
3
|
from __future__ import annotations
|
|
4
4
|
|
|
5
|
+
from enum import Enum
|
|
5
6
|
from typing import Any
|
|
6
7
|
|
|
7
8
|
from pydantic import BaseModel
|
|
@@ -14,6 +15,25 @@ from cmdop.exceptions import (
|
|
|
14
15
|
)
|
|
15
16
|
|
|
16
17
|
|
|
18
|
+
class WaitUntil(str, Enum):
|
|
19
|
+
"""Wait strategy for navigation.
|
|
20
|
+
|
|
21
|
+
Determines when navigation is considered complete.
|
|
22
|
+
"""
|
|
23
|
+
|
|
24
|
+
LOAD = "load"
|
|
25
|
+
"""Wait for load event (default, not recommended for SPA)."""
|
|
26
|
+
|
|
27
|
+
DOMCONTENTLOADED = "domcontentloaded"
|
|
28
|
+
"""Wait for DOMContentLoaded event."""
|
|
29
|
+
|
|
30
|
+
NETWORKIDLE = "networkidle"
|
|
31
|
+
"""Wait until no network activity for 500ms (best for SPA)."""
|
|
32
|
+
|
|
33
|
+
COMMIT = "commit"
|
|
34
|
+
"""Return immediately after navigation commits (fastest)."""
|
|
35
|
+
|
|
36
|
+
|
|
17
37
|
def raise_browser_error(error: str, operation: str, **context: Any) -> None:
|
|
18
38
|
"""Raise appropriate browser exception based on error message."""
|
|
19
39
|
error_lower = error.lower()
|
|
@@ -115,3 +135,86 @@ class InfiniteScrollResult(BaseModel):
|
|
|
115
135
|
at_bottom: bool = False
|
|
116
136
|
total_seen: int = 0
|
|
117
137
|
error: str | None = None
|
|
138
|
+
|
|
139
|
+
|
|
140
|
+
# =============================================================================
|
|
141
|
+
# Network Capture Models (v2.19.0)
|
|
142
|
+
# =============================================================================
|
|
143
|
+
|
|
144
|
+
|
|
145
|
+
class NetworkRequest(BaseModel):
|
|
146
|
+
"""Captured HTTP request."""
|
|
147
|
+
|
|
148
|
+
url: str = ""
|
|
149
|
+
method: str = "GET"
|
|
150
|
+
headers: dict[str, str] = {}
|
|
151
|
+
body: bytes = b""
|
|
152
|
+
content_type: str = ""
|
|
153
|
+
resource_type: str = "" # document, script, xhr, fetch, image, etc.
|
|
154
|
+
|
|
155
|
+
|
|
156
|
+
class NetworkResponse(BaseModel):
|
|
157
|
+
"""Captured HTTP response."""
|
|
158
|
+
|
|
159
|
+
status: int = 0
|
|
160
|
+
status_text: str = ""
|
|
161
|
+
headers: dict[str, str] = {}
|
|
162
|
+
body: bytes = b""
|
|
163
|
+
content_type: str = ""
|
|
164
|
+
size: int = 0
|
|
165
|
+
from_cache: bool = False
|
|
166
|
+
|
|
167
|
+
|
|
168
|
+
class NetworkTiming(BaseModel):
|
|
169
|
+
"""Request timing data."""
|
|
170
|
+
|
|
171
|
+
started_at_ms: int = 0
|
|
172
|
+
ended_at_ms: int = 0
|
|
173
|
+
duration_ms: int = 0
|
|
174
|
+
wait_time_ms: int = 0 # Time to first byte
|
|
175
|
+
receive_time_ms: int = 0 # Time to download body
|
|
176
|
+
|
|
177
|
+
|
|
178
|
+
class NetworkExchange(BaseModel):
|
|
179
|
+
"""Complete request/response exchange."""
|
|
180
|
+
|
|
181
|
+
id: str = ""
|
|
182
|
+
request: NetworkRequest = NetworkRequest()
|
|
183
|
+
response: NetworkResponse | None = None
|
|
184
|
+
timing: NetworkTiming = NetworkTiming()
|
|
185
|
+
error: str = ""
|
|
186
|
+
frame_id: str = ""
|
|
187
|
+
initiator: str = "" # URL or script that initiated
|
|
188
|
+
|
|
189
|
+
def json_body(self) -> Any:
|
|
190
|
+
"""Parse response body as JSON."""
|
|
191
|
+
import json
|
|
192
|
+
if self.response and self.response.body:
|
|
193
|
+
return json.loads(self.response.body)
|
|
194
|
+
return None
|
|
195
|
+
|
|
196
|
+
def text_body(self) -> str:
|
|
197
|
+
"""Get response body as text."""
|
|
198
|
+
if self.response and self.response.body:
|
|
199
|
+
return self.response.body.decode("utf-8", errors="replace")
|
|
200
|
+
return ""
|
|
201
|
+
|
|
202
|
+
|
|
203
|
+
class NetworkStats(BaseModel):
|
|
204
|
+
"""Network capture statistics."""
|
|
205
|
+
|
|
206
|
+
enabled: bool = False
|
|
207
|
+
total_captured: int = 0
|
|
208
|
+
total_errors: int = 0
|
|
209
|
+
total_bytes: int = 0
|
|
210
|
+
average_duration_ms: int = 0
|
|
211
|
+
|
|
212
|
+
|
|
213
|
+
class NetworkFilter(BaseModel):
|
|
214
|
+
"""Filter for querying captured exchanges."""
|
|
215
|
+
|
|
216
|
+
url_pattern: str = ""
|
|
217
|
+
methods: list[str] = []
|
|
218
|
+
status_codes: list[int] = []
|
|
219
|
+
resource_types: list[str] = []
|
|
220
|
+
limit: int = 0
|
|
@@ -7,7 +7,7 @@ from typing import TYPE_CHECKING, Any
|
|
|
7
7
|
|
|
8
8
|
from cmdop.services.base import BaseService
|
|
9
9
|
from cmdop.services.browser.service._helpers import BaseServiceMixin, cookie_to_pb, pb_to_cookie
|
|
10
|
-
from cmdop.services.browser.models import BrowserCookie, BrowserState, PageInfo, raise_browser_error
|
|
10
|
+
from cmdop.services.browser.models import BrowserCookie, BrowserState, PageInfo, WaitUntil, raise_browser_error
|
|
11
11
|
|
|
12
12
|
if TYPE_CHECKING:
|
|
13
13
|
from cmdop.transport.base import BaseTransport
|
|
@@ -75,11 +75,31 @@ class BrowserService(BaseService, BaseServiceMixin):
|
|
|
75
75
|
|
|
76
76
|
# === Navigation & Interaction ===
|
|
77
77
|
|
|
78
|
-
def navigate(
|
|
79
|
-
|
|
78
|
+
def navigate(
|
|
79
|
+
self,
|
|
80
|
+
session_id: str,
|
|
81
|
+
url: str,
|
|
82
|
+
timeout_ms: int = 30000,
|
|
83
|
+
wait_until: WaitUntil = WaitUntil.LOAD,
|
|
84
|
+
) -> str:
|
|
85
|
+
from cmdop._generated.rpc_messages.browser_pb2 import (
|
|
86
|
+
BrowserNavigateRequest,
|
|
87
|
+
WaitUntil as PbWaitUntil,
|
|
88
|
+
)
|
|
89
|
+
|
|
90
|
+
# Convert Python enum to proto enum
|
|
91
|
+
pb_wait_until = {
|
|
92
|
+
WaitUntil.LOAD: PbWaitUntil.WAIT_LOAD,
|
|
93
|
+
WaitUntil.DOMCONTENTLOADED: PbWaitUntil.WAIT_DOMCONTENTLOADED,
|
|
94
|
+
WaitUntil.NETWORKIDLE: PbWaitUntil.WAIT_NETWORKIDLE,
|
|
95
|
+
WaitUntil.COMMIT: PbWaitUntil.WAIT_COMMIT,
|
|
96
|
+
}.get(wait_until, PbWaitUntil.WAIT_LOAD)
|
|
80
97
|
|
|
81
98
|
request = BrowserNavigateRequest(
|
|
82
|
-
browser_session_id=session_id,
|
|
99
|
+
browser_session_id=session_id,
|
|
100
|
+
url=url,
|
|
101
|
+
timeout_ms=timeout_ms,
|
|
102
|
+
wait_until=pb_wait_until,
|
|
83
103
|
)
|
|
84
104
|
response = self._call_sync(self._get_stub.BrowserNavigate, request)
|
|
85
105
|
|
|
@@ -434,3 +454,183 @@ class BrowserService(BaseService, BaseServiceMixin):
|
|
|
434
454
|
"items": json.loads(response.items_json) if response.items_json else [],
|
|
435
455
|
"count": response.count,
|
|
436
456
|
}
|
|
457
|
+
|
|
458
|
+
# === Network Capture (v2.19.0) ===
|
|
459
|
+
|
|
460
|
+
def network_enable(
|
|
461
|
+
self, session_id: str, max_exchanges: int = 1000, max_response_size: int = 10_000_000
|
|
462
|
+
) -> None:
|
|
463
|
+
"""Enable network capture."""
|
|
464
|
+
from cmdop._generated.rpc_messages.browser_pb2 import BrowserNetworkEnableRequest
|
|
465
|
+
|
|
466
|
+
request = BrowserNetworkEnableRequest(
|
|
467
|
+
browser_session_id=session_id,
|
|
468
|
+
max_exchanges=max_exchanges,
|
|
469
|
+
max_response_size=max_response_size,
|
|
470
|
+
)
|
|
471
|
+
response = self._call_sync(self._get_stub.BrowserNetworkEnable, request)
|
|
472
|
+
|
|
473
|
+
if not response.success:
|
|
474
|
+
raise RuntimeError(f"NetworkEnable failed: {response.error}")
|
|
475
|
+
|
|
476
|
+
def network_disable(self, session_id: str) -> None:
|
|
477
|
+
"""Disable network capture."""
|
|
478
|
+
from cmdop._generated.rpc_messages.browser_pb2 import BrowserNetworkDisableRequest
|
|
479
|
+
|
|
480
|
+
request = BrowserNetworkDisableRequest(browser_session_id=session_id)
|
|
481
|
+
response = self._call_sync(self._get_stub.BrowserNetworkDisable, request)
|
|
482
|
+
|
|
483
|
+
if not response.success:
|
|
484
|
+
raise RuntimeError(f"NetworkDisable failed: {response.error}")
|
|
485
|
+
|
|
486
|
+
def network_get_exchanges(
|
|
487
|
+
self,
|
|
488
|
+
session_id: str,
|
|
489
|
+
url_pattern: str = "",
|
|
490
|
+
methods: list[str] | None = None,
|
|
491
|
+
status_codes: list[int] | None = None,
|
|
492
|
+
resource_types: list[str] | None = None,
|
|
493
|
+
limit: int = 0,
|
|
494
|
+
) -> dict:
|
|
495
|
+
"""Get captured exchanges."""
|
|
496
|
+
from cmdop._generated.rpc_messages.browser_pb2 import BrowserNetworkGetExchangesRequest
|
|
497
|
+
|
|
498
|
+
request = BrowserNetworkGetExchangesRequest(
|
|
499
|
+
browser_session_id=session_id,
|
|
500
|
+
url_pattern=url_pattern,
|
|
501
|
+
methods=methods or [],
|
|
502
|
+
status_codes=status_codes or [],
|
|
503
|
+
resource_types=resource_types or [],
|
|
504
|
+
limit=limit,
|
|
505
|
+
)
|
|
506
|
+
response = self._call_sync(self._get_stub.BrowserNetworkGetExchanges, request)
|
|
507
|
+
|
|
508
|
+
if not response.success:
|
|
509
|
+
raise RuntimeError(f"NetworkGetExchanges failed: {response.error}")
|
|
510
|
+
|
|
511
|
+
return {
|
|
512
|
+
"exchanges": [self._pb_to_exchange(e) for e in response.exchanges],
|
|
513
|
+
"count": response.count,
|
|
514
|
+
}
|
|
515
|
+
|
|
516
|
+
def network_get_exchange(self, session_id: str, exchange_id: str) -> dict:
|
|
517
|
+
"""Get specific exchange by ID."""
|
|
518
|
+
from cmdop._generated.rpc_messages.browser_pb2 import BrowserNetworkGetExchangeRequest
|
|
519
|
+
|
|
520
|
+
request = BrowserNetworkGetExchangeRequest(
|
|
521
|
+
browser_session_id=session_id, exchange_id=exchange_id
|
|
522
|
+
)
|
|
523
|
+
response = self._call_sync(self._get_stub.BrowserNetworkGetExchange, request)
|
|
524
|
+
|
|
525
|
+
if not response.success:
|
|
526
|
+
raise RuntimeError(f"NetworkGetExchange failed: {response.error}")
|
|
527
|
+
|
|
528
|
+
return {"exchange": self._pb_to_exchange(response.exchange) if response.exchange else None}
|
|
529
|
+
|
|
530
|
+
def network_get_last(self, session_id: str, url_pattern: str = "") -> dict:
|
|
531
|
+
"""Get most recent exchange matching URL pattern."""
|
|
532
|
+
from cmdop._generated.rpc_messages.browser_pb2 import BrowserNetworkGetLastRequest
|
|
533
|
+
|
|
534
|
+
request = BrowserNetworkGetLastRequest(
|
|
535
|
+
browser_session_id=session_id, url_pattern=url_pattern
|
|
536
|
+
)
|
|
537
|
+
response = self._call_sync(self._get_stub.BrowserNetworkGetLast, request)
|
|
538
|
+
|
|
539
|
+
if not response.success:
|
|
540
|
+
raise RuntimeError(f"NetworkGetLast failed: {response.error}")
|
|
541
|
+
|
|
542
|
+
return {"exchange": self._pb_to_exchange(response.exchange) if response.exchange else None}
|
|
543
|
+
|
|
544
|
+
def network_clear(self, session_id: str) -> None:
|
|
545
|
+
"""Clear all captured exchanges."""
|
|
546
|
+
from cmdop._generated.rpc_messages.browser_pb2 import BrowserNetworkClearRequest
|
|
547
|
+
|
|
548
|
+
request = BrowserNetworkClearRequest(browser_session_id=session_id)
|
|
549
|
+
response = self._call_sync(self._get_stub.BrowserNetworkClear, request)
|
|
550
|
+
|
|
551
|
+
if not response.success:
|
|
552
|
+
raise RuntimeError(f"NetworkClear failed: {response.error}")
|
|
553
|
+
|
|
554
|
+
def network_stats(self, session_id: str) -> dict:
|
|
555
|
+
"""Get capture statistics."""
|
|
556
|
+
from cmdop._generated.rpc_messages.browser_pb2 import BrowserNetworkStatsRequest
|
|
557
|
+
|
|
558
|
+
request = BrowserNetworkStatsRequest(browser_session_id=session_id)
|
|
559
|
+
response = self._call_sync(self._get_stub.BrowserNetworkStats, request)
|
|
560
|
+
|
|
561
|
+
if not response.success:
|
|
562
|
+
raise RuntimeError(f"NetworkStats failed: {response.error}")
|
|
563
|
+
|
|
564
|
+
return {
|
|
565
|
+
"enabled": response.enabled,
|
|
566
|
+
"total_captured": response.total_captured,
|
|
567
|
+
"total_errors": response.total_errors,
|
|
568
|
+
"total_bytes": response.total_bytes,
|
|
569
|
+
"average_duration_ms": response.average_duration_ms,
|
|
570
|
+
}
|
|
571
|
+
|
|
572
|
+
def network_export_har(
|
|
573
|
+
self,
|
|
574
|
+
session_id: str,
|
|
575
|
+
url_pattern: str = "",
|
|
576
|
+
methods: list[str] | None = None,
|
|
577
|
+
status_codes: list[int] | None = None,
|
|
578
|
+
resource_types: list[str] | None = None,
|
|
579
|
+
) -> dict:
|
|
580
|
+
"""Export captured exchanges to HAR format."""
|
|
581
|
+
from cmdop._generated.rpc_messages.browser_pb2 import BrowserNetworkExportHARRequest
|
|
582
|
+
|
|
583
|
+
request = BrowserNetworkExportHARRequest(
|
|
584
|
+
browser_session_id=session_id,
|
|
585
|
+
url_pattern=url_pattern,
|
|
586
|
+
methods=methods or [],
|
|
587
|
+
status_codes=status_codes or [],
|
|
588
|
+
resource_types=resource_types or [],
|
|
589
|
+
)
|
|
590
|
+
response = self._call_sync(self._get_stub.BrowserNetworkExportHAR, request)
|
|
591
|
+
|
|
592
|
+
if not response.success:
|
|
593
|
+
raise RuntimeError(f"NetworkExportHAR failed: {response.error}")
|
|
594
|
+
|
|
595
|
+
return {"har_data": response.har_data}
|
|
596
|
+
|
|
597
|
+
def _pb_to_exchange(self, pb: Any) -> dict:
|
|
598
|
+
"""Convert protobuf exchange to dict."""
|
|
599
|
+
result: dict[str, Any] = {
|
|
600
|
+
"id": pb.id,
|
|
601
|
+
"error": pb.error,
|
|
602
|
+
"frame_id": pb.frame_id,
|
|
603
|
+
"initiator": pb.initiator,
|
|
604
|
+
}
|
|
605
|
+
|
|
606
|
+
if pb.request:
|
|
607
|
+
result["request"] = {
|
|
608
|
+
"url": pb.request.url,
|
|
609
|
+
"method": pb.request.method,
|
|
610
|
+
"headers": dict(pb.request.headers),
|
|
611
|
+
"body": pb.request.body,
|
|
612
|
+
"content_type": pb.request.content_type,
|
|
613
|
+
"resource_type": pb.request.resource_type,
|
|
614
|
+
}
|
|
615
|
+
|
|
616
|
+
if pb.response:
|
|
617
|
+
result["response"] = {
|
|
618
|
+
"status": pb.response.status,
|
|
619
|
+
"status_text": pb.response.status_text,
|
|
620
|
+
"headers": dict(pb.response.headers),
|
|
621
|
+
"body": pb.response.body,
|
|
622
|
+
"content_type": pb.response.content_type,
|
|
623
|
+
"size": pb.response.size,
|
|
624
|
+
"from_cache": pb.response.from_cache,
|
|
625
|
+
}
|
|
626
|
+
|
|
627
|
+
if pb.timing:
|
|
628
|
+
result["timing"] = {
|
|
629
|
+
"started_at_ms": pb.timing.started_at_ms,
|
|
630
|
+
"ended_at_ms": pb.timing.ended_at_ms,
|
|
631
|
+
"duration_ms": pb.timing.duration_ms,
|
|
632
|
+
"wait_time_ms": pb.timing.wait_time_ms,
|
|
633
|
+
"receive_time_ms": pb.timing.receive_time_ms,
|
|
634
|
+
}
|
|
635
|
+
|
|
636
|
+
return result
|
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
from __future__ import annotations
|
|
4
4
|
from typing import TYPE_CHECKING, Any
|
|
5
5
|
|
|
6
|
-
from cmdop.services.browser.models import BrowserCookie, BrowserState, PageInfo
|
|
6
|
+
from cmdop.services.browser.models import BrowserCookie, BrowserState, PageInfo, WaitUntil
|
|
7
7
|
|
|
8
8
|
from .capabilities import (
|
|
9
9
|
ScrollCapability,
|
|
@@ -11,6 +11,8 @@ from .capabilities import (
|
|
|
11
11
|
TimingCapability,
|
|
12
12
|
DOMCapability,
|
|
13
13
|
FetchCapability,
|
|
14
|
+
NetworkCapability,
|
|
15
|
+
VisualCapability,
|
|
14
16
|
)
|
|
15
17
|
|
|
16
18
|
if TYPE_CHECKING:
|
|
@@ -51,6 +53,8 @@ class BrowserSession:
|
|
|
51
53
|
"_timing",
|
|
52
54
|
"_dom",
|
|
53
55
|
"_fetch",
|
|
56
|
+
"_network",
|
|
57
|
+
"_visual",
|
|
54
58
|
)
|
|
55
59
|
|
|
56
60
|
def __init__(self, service: "BrowserService", session_id: str) -> None:
|
|
@@ -61,6 +65,8 @@ class BrowserSession:
|
|
|
61
65
|
self._timing: TimingCapability | None = None
|
|
62
66
|
self._dom: DOMCapability | None = None
|
|
63
67
|
self._fetch: FetchCapability | None = None
|
|
68
|
+
self._network: NetworkCapability | None = None
|
|
69
|
+
self._visual: VisualCapability | None = None
|
|
64
70
|
|
|
65
71
|
@property
|
|
66
72
|
def session_id(self) -> str:
|
|
@@ -103,11 +109,43 @@ class BrowserSession:
|
|
|
103
109
|
self._fetch = FetchCapability(self)
|
|
104
110
|
return self._fetch
|
|
105
111
|
|
|
112
|
+
@property
|
|
113
|
+
def network(self) -> NetworkCapability:
|
|
114
|
+
"""Network: enable(), disable(), get_all(), filter(), last(), clear(), stats()"""
|
|
115
|
+
if self._network is None:
|
|
116
|
+
self._network = NetworkCapability(self)
|
|
117
|
+
return self._network
|
|
118
|
+
|
|
119
|
+
@property
|
|
120
|
+
def visual(self) -> VisualCapability:
|
|
121
|
+
"""Visual: toast(), click(), move(), highlight(), hide_highlight(), clear_trail(), set_state()"""
|
|
122
|
+
if self._visual is None:
|
|
123
|
+
self._visual = VisualCapability(self)
|
|
124
|
+
return self._visual
|
|
125
|
+
|
|
106
126
|
# === Core Methods ===
|
|
107
127
|
|
|
108
|
-
def navigate(
|
|
109
|
-
|
|
110
|
-
|
|
128
|
+
def navigate(
|
|
129
|
+
self,
|
|
130
|
+
url: str,
|
|
131
|
+
timeout_ms: int = 30000,
|
|
132
|
+
wait_until: WaitUntil = WaitUntil.LOAD,
|
|
133
|
+
) -> str:
|
|
134
|
+
"""Navigate to URL with specified wait strategy.
|
|
135
|
+
|
|
136
|
+
Args:
|
|
137
|
+
url: URL to navigate to.
|
|
138
|
+
timeout_ms: Timeout in milliseconds.
|
|
139
|
+
wait_until: When navigation is considered complete:
|
|
140
|
+
- WaitUntil.LOAD: Wait for load event (default, slow for SPA)
|
|
141
|
+
- WaitUntil.DOMCONTENTLOADED: Wait for DOMContentLoaded event
|
|
142
|
+
- WaitUntil.NETWORKIDLE: Wait until network is idle (best for SPA)
|
|
143
|
+
- WaitUntil.COMMIT: Return immediately (fastest)
|
|
144
|
+
|
|
145
|
+
Returns:
|
|
146
|
+
Final URL after navigation (may differ due to redirects).
|
|
147
|
+
"""
|
|
148
|
+
return self._service.navigate(self._session_id, url, timeout_ms, wait_until)
|
|
111
149
|
|
|
112
150
|
def click(self, selector: str, timeout_ms: int = 5000, move_cursor: bool = False) -> None:
|
|
113
151
|
"""Click element by CSS selector."""
|