-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathstart_profile.py
More file actions
60 lines (46 loc) · 1.51 KB
/
start_profile.py
File metadata and controls
60 lines (46 loc) · 1.51 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
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
"""
Start a Multilogin profile, wait briefly, then stop it.
Usage (Windows PowerShell):
$env:MULTILOGIN_TOKEN="your-token"
$env:MULTILOGIN_PROFILE_ID="profile-uuid"
python start_profile.py
"""
import os
import sys
import time
from load_env import bootstrap_env
from multilogin_client import MultiloginClient, MultiloginError
bootstrap_env()
def main() -> None:
profile_id = os.environ.get("MULTILOGIN_PROFILE_ID", "")
if not profile_id:
print("Set MULTILOGIN_PROFILE_ID to a profile UUID.", file=sys.stderr)
sys.exit(1)
try:
client = MultiloginClient()
except MultiloginError as exc:
print(f"Error: {exc}", file=sys.stderr)
sys.exit(1)
print(f"Starting profile {profile_id}...")
try:
session = client.start_profile(profile_id)
except MultiloginError as exc:
print(f"Start failed: {exc}", file=sys.stderr)
sys.exit(1)
print("Session:", session)
cdp = client.extract_cdp_url(session)
if cdp:
print(f"CDP hint: {cdp}")
print("For Playwright: set MULTILOGIN_CDP_URL and run playwright_connect.py")
wait = int(os.environ.get("MULTILOGIN_DEMO_WAIT", "10"))
print(f"Running {wait}s (override with MULTILOGIN_DEMO_WAIT)...")
time.sleep(wait)
print(f"Stopping profile {profile_id}...")
try:
client.stop_profile(profile_id)
except MultiloginError as exc:
print(f"Stop failed: {exc}", file=sys.stderr)
sys.exit(1)
print("Done.")
if __name__ == "__main__":
main()