forked from Priyanshu-hawk/ChatGPT-unofficial-api-selenium
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathchrome_handler.py
41 lines (32 loc) · 1.27 KB
/
chrome_handler.py
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
import os
import subprocess
import time
import sys
import platform
def get_chrome_path():
os_name = platform.system().lower()
if os_name == "darwin":
return "/Applications/Google Chrome.app/Contents/MacOS/Google Chrome"
elif os_name == "windows":
chrome_32bit_path = "C:\\Program Files (x86)\\Google\\Chrome\\Application\\chrome.exe"
chrome_64bit_path = "C:\\Program Files\\Google\\Chrome\\Application\\chrome.exe"
if os.path.exists(chrome_32bit_path):
return chrome_32bit_path
elif os.path.exists(chrome_64bit_path):
return chrome_64bit_path
else:
raise FileNotFoundError("Chrome executable not found in either 32-bit or 64-bit directories.")
elif os_name == "linux":
return "/usr/bin/google-chrome"
else:
raise Exception(f"Unsupported OS: {os_name}")
def start_chrome():
chrome_path = get_chrome_path()
subprocess.Popen([f'{chrome_path}','--remote-debugging-port=9222','--user-data-dir=chromedata'],stdout = subprocess.PIPE, stderr = subprocess.PIPE)
def kill_chrome():
subprocess.run(['killall','chrome'])
if __name__ == "__main__":
if sys.argv[1] == "s":
start_chrome()
elif sys.argv[1] == "k":
kill_chrome()