Update api.txt
Browse files
api.txt
CHANGED
|
@@ -365,16 +365,16 @@ async def open_browser(request: Request):
|
|
| 365 |
error_data = {"success": False, "msg": f"chrome端口{port}未就绪", "data": {}}
|
| 366 |
return encrypt_json_response(error_data)
|
| 367 |
async with httpx.AsyncClient() as client:
|
| 368 |
-
resp = await client.get(f"http
|
| 369 |
if resp.status_code == 200:
|
| 370 |
browser_info = resp.json()
|
| 371 |
-
ws_url = browser_info.get("webSocketDebuggerUrl").replace("ws
|
| 372 |
# 去掉端口号
|
| 373 |
ws_url = re.sub(r":\d+", "", ws_url)
|
| 374 |
logger.info(f"Browser opened with ID: {browser_id}, Info: {browser_info}")
|
| 375 |
BROWSERS[browser_id] = {"process": proc, "ws": ws_url, "port": port, "status": "open", "info": browser_info}
|
| 376 |
response_data = {"success": True, "msg": "success", "data": {"id": browser_id, "ws": ws_url}, "info": browser_info}
|
| 377 |
-
|
| 378 |
return response_data
|
| 379 |
|
| 380 |
|
|
@@ -390,7 +390,7 @@ async def close_browser(request: Request):
|
|
| 390 |
b["process"].terminate()
|
| 391 |
b["status"] = "closed"
|
| 392 |
response_data = {"success": True, "msg": "closed", "data": {"id": browser_id}}
|
| 393 |
-
|
| 394 |
return response_data
|
| 395 |
|
| 396 |
|
|
@@ -413,7 +413,7 @@ async def delete_browser(request: Request):
|
|
| 413 |
import shutil
|
| 414 |
shutil.rmtree(profile_dir, ignore_errors=True)
|
| 415 |
response_data = {"success": True, "msg": "deleted", "data": {"id": browser_id}}
|
| 416 |
-
|
| 417 |
return response_data
|
| 418 |
|
| 419 |
|
|
@@ -443,7 +443,7 @@ async def browser_ports():
|
|
| 443 |
@app.post("/health")
|
| 444 |
async def health():
|
| 445 |
response_data = {"success": True, "msg": "ok"}
|
| 446 |
-
|
| 447 |
return response_data
|
| 448 |
|
| 449 |
|
|
@@ -518,7 +518,7 @@ async def find_browser_by_target_id(tab_type,target_id: str):
|
|
| 518 |
# 尝试获取浏览器的页面列表
|
| 519 |
port = browser["port"]
|
| 520 |
async with httpx.AsyncClient() as client:
|
| 521 |
-
resp = await client.get(f"http
|
| 522 |
if resp.status_code == 200:
|
| 523 |
pages = resp.json()
|
| 524 |
# 检查页面是否包含 target_id
|
|
@@ -552,7 +552,7 @@ async def cdp_native_proxy(request: Request):
|
|
| 552 |
port = b["port"]
|
| 553 |
# 2. 构造目标URL
|
| 554 |
path = request.url.path
|
| 555 |
-
url = f"http
|
| 556 |
# 3. 代理请求
|
| 557 |
headers = dict(request.headers)
|
| 558 |
headers["host"] = "127.0.0.1"
|
|
@@ -587,7 +587,7 @@ async def cdp_native_ws_proxy(websocket: WebSocket, tab_type: str, target_id: st
|
|
| 587 |
tab_type = "page" if tab_type == "page" else "browser"
|
| 588 |
logger.info(f"WebSocket连接: {browser}")
|
| 589 |
port = browser["port"]
|
| 590 |
-
target_url = f"ws
|
| 591 |
logger.info(f"Forwarding to: {target_url}")
|
| 592 |
|
| 593 |
try:
|
|
|
|
| 365 |
error_data = {"success": False, "msg": f"chrome端口{port}未就绪", "data": {}}
|
| 366 |
return encrypt_json_response(error_data)
|
| 367 |
async with httpx.AsyncClient() as client:
|
| 368 |
+
resp = await client.get(f"http:#127.0.0.1:{port}/json/version")
|
| 369 |
if resp.status_code == 200:
|
| 370 |
browser_info = resp.json()
|
| 371 |
+
ws_url = browser_info.get("webSocketDebuggerUrl").replace("ws:#127.0.0.1", "wss:#0.0.0.0")
|
| 372 |
# 去掉端口号
|
| 373 |
ws_url = re.sub(r":\d+", "", ws_url)
|
| 374 |
logger.info(f"Browser opened with ID: {browser_id}, Info: {browser_info}")
|
| 375 |
BROWSERS[browser_id] = {"process": proc, "ws": ws_url, "port": port, "status": "open", "info": browser_info}
|
| 376 |
response_data = {"success": True, "msg": "success", "data": {"id": browser_id, "ws": ws_url}, "info": browser_info}
|
| 377 |
+
# return encrypt_json_response(response_data)
|
| 378 |
return response_data
|
| 379 |
|
| 380 |
|
|
|
|
| 390 |
b["process"].terminate()
|
| 391 |
b["status"] = "closed"
|
| 392 |
response_data = {"success": True, "msg": "closed", "data": {"id": browser_id}}
|
| 393 |
+
# return encrypt_json_response(response_data)
|
| 394 |
return response_data
|
| 395 |
|
| 396 |
|
|
|
|
| 413 |
import shutil
|
| 414 |
shutil.rmtree(profile_dir, ignore_errors=True)
|
| 415 |
response_data = {"success": True, "msg": "deleted", "data": {"id": browser_id}}
|
| 416 |
+
# return encrypt_json_response(response_data)
|
| 417 |
return response_data
|
| 418 |
|
| 419 |
|
|
|
|
| 443 |
@app.post("/health")
|
| 444 |
async def health():
|
| 445 |
response_data = {"success": True, "msg": "ok"}
|
| 446 |
+
# return encrypt_json_response(response_data)
|
| 447 |
return response_data
|
| 448 |
|
| 449 |
|
|
|
|
| 518 |
# 尝试获取浏览器的页面列表
|
| 519 |
port = browser["port"]
|
| 520 |
async with httpx.AsyncClient() as client:
|
| 521 |
+
resp = await client.get(f"http:#127.0.0.1:{port}/json/list")
|
| 522 |
if resp.status_code == 200:
|
| 523 |
pages = resp.json()
|
| 524 |
# 检查页面是否包含 target_id
|
|
|
|
| 552 |
port = b["port"]
|
| 553 |
# 2. 构造目标URL
|
| 554 |
path = request.url.path
|
| 555 |
+
url = f"http:#127.0.0.1:{port}{path}"
|
| 556 |
# 3. 代理请求
|
| 557 |
headers = dict(request.headers)
|
| 558 |
headers["host"] = "127.0.0.1"
|
|
|
|
| 587 |
tab_type = "page" if tab_type == "page" else "browser"
|
| 588 |
logger.info(f"WebSocket连接: {browser}")
|
| 589 |
port = browser["port"]
|
| 590 |
+
target_url = f"ws:#127.0.0.1:{port}/devtools/{tab_type}/{target_id}"
|
| 591 |
logger.info(f"Forwarding to: {target_url}")
|
| 592 |
|
| 593 |
try:
|