-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest_chrome_extraction.py
More file actions
executable file
·119 lines (103 loc) · 3.74 KB
/
test_chrome_extraction.py
File metadata and controls
executable file
·119 lines (103 loc) · 3.74 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
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
"""
Test script for extracting assistant IDs from Chrome tabs
"""
import os
import sys
import subprocess
import re
from typing import List, Optional, Tuple
def get_foreground_tab_url() -> str:
"""Get URL from the active Chrome tab"""
script = '''
tell application "Google Chrome"
get URL of active tab of front window
end tell
'''
try:
result = subprocess.run(['osascript', '-e', script],
capture_output=True, text=True, check=True)
return result.stdout.strip()
except subprocess.CalledProcessError as e:
print(f"Error: Could not get URL from Chrome: {e}")
print(f"stderr: {e.stderr}")
return ""
def get_chrome_tabs() -> List[str]:
"""Get URLs from all Chrome tabs"""
script = '''
tell application "Google Chrome"
set tabList to {}
set windowList to every window
repeat with theWindow in windowList
set tabList to tabList & (URL of every tab of theWindow)
end repeat
return tabList
end tell
'''
try:
result = subprocess.run(['osascript', '-e', script],
capture_output=True, text=True, check=True)
return result.stdout.strip().split(', ')
except subprocess.CalledProcessError as e:
print(f"Error: Could not get URLs from Chrome: {e}")
print(f"stderr: {e.stderr}")
return []
def extract_assistant_id(url: str) -> Optional[str]:
"""Extract assistant ID from URL"""
match = re.search(r'assistantId=([^&]+)', url)
if match:
return match.group(1)
return None
def find_vapi_tabs() -> List[Tuple[str, str]]:
"""Find all Chrome tabs with VAPI assistant IDs"""
all_tabs = get_chrome_tabs()
vapi_tabs = []
for url in all_tabs:
assistant_id = extract_assistant_id(url)
if assistant_id:
vapi_tabs.append((url, assistant_id))
return vapi_tabs
def main():
print("Testing Chrome URL extraction...")
# Test foreground tab URL
print("\n=== TEST 1: Get foreground tab URL ===")
foreground_url = get_foreground_tab_url()
print(f"Foreground tab URL: {foreground_url}")
# Test foreground tab assistant ID extraction
print("\n=== TEST 2: Extract assistant ID from foreground tab ===")
foreground_assistant_id = extract_assistant_id(foreground_url)
if foreground_assistant_id:
print(f"Found assistant ID: {foreground_assistant_id}")
else:
print("No assistant ID found in foreground tab")
# Test all Chrome tabs
print("\n=== TEST 3: Get all Chrome tabs ===")
all_tabs = get_chrome_tabs()
print(f"Found {len(all_tabs)} Chrome tabs")
# Test finding all VAPI tabs
print("\n=== TEST 4: Find all VAPI tabs ===")
vapi_tabs = find_vapi_tabs()
if vapi_tabs:
print(f"Found {len(vapi_tabs)} VAPI tabs:")
for i, (url, assistant_id) in enumerate(vapi_tabs):
print(f" {i+1}. URL: {url}")
print(f" ID: {assistant_id}")
else:
print("No VAPI tabs found")
# Test specific URL
test_url = "https://dashboard.vapi.ai/calls?assistantId=a37edc9f-852d-41b3-8601-801c20292716"
print(f"\n=== TEST 5: Extract ID from specific URL ===")
print(f"URL: {test_url}")
test_id = extract_assistant_id(test_url)
print(f"Extracted ID: {test_id}")
# Verify it matches expected ID
expected_id = "a37edc9f-852d-41b3-8601-801c20292716"
if test_id == expected_id:
print("✅ ID matches expected value")
else:
print("❌ ID doesn't match expected value")
print(f"Expected: {expected_id}")
print(f"Got: {test_id}")
if __name__ == "__main__":
main()