-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathbrowser_telemetry.py
More file actions
32 lines (23 loc) · 1.09 KB
/
Copy pathbrowser_telemetry.py
File metadata and controls
32 lines (23 loc) · 1.09 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
"""Example: stream live browser telemetry events from a session."""
from kernel import Kernel
def main() -> None:
client = Kernel()
# Enable telemetry capture when creating the browser.
browser = client.browsers.create(telemetry={"enabled": True})
try:
# Telemetry is a default direct-to-VM routing subresource, so the stream
# connects straight to the browser VM automatically.
stream = client.browsers.telemetry.stream(browser.session_id)
# Make a few browser activity calls to generate events. The "api" telemetry
# category emits an event per VM API call, so events arrive within ~1s.
for _ in range(3):
client.browsers.curl(browser.session_id, url="https://example.com", method="GET")
# Print a few events, then stop so we don't wait on the 15s keepalive.
for count, message in enumerate(stream, start=1):
print(message.seq, message.event.type)
if count >= 3:
break
finally:
client.browsers.delete_by_id(browser.session_id)
if __name__ == "__main__":
main()