Случай использования:
< ol>
[*].bat запускает автоматическое воспроизведение, где я получаю идентификатор сеанса и передаю его отладчику.
[*]connect_debugger_async подключается к текущему сеансу Chrome на основе идентификатора сеанса, и я вижу «отладчик прикреплен». ' сообщение в консоли командной строки cmd.
[*]Аналогично, когда я вызываю действие Pause_debugger из Python, я вижу, что команда достигает командной строки, и действие паузы действительно происходит в отладчике, где выполнение сценария приостанавливается.
[*]Но когда вызывается Disconnect_debugger, я вижу, что команда достигает командной строки, но она не завершена.
Ожидается: Я ожидаю, что в Disconnect_debugger курсор должен выйти из командной строки и указать на текущий рабочий каталог.
Пример: C:/Temp
< Strong>Реально: При отключении_отладчика курсор не выходит из командной строки и закрывается только тогда, когда я закрываю приложение tkinter.
Ниже приведен мой фрагмент кода:
Код: Выделить всё
import subprocess
import asyncio
import websockets
import json
import tkinter as tk
from tkinter import messagebox
class DebuggerControlApp(tk.Tk):
def __init__(self):
super().__init__()
self.title("Debugger Control")
self.geometry("300x200")
self.launch_button = tk.Button(self, text="Launch Browser", command=self.launch_browser)
self.launch_button.pack(pady=10)
self.connect_button = tk.Button(self, text="Connect Debugger", command=self.connect_debugger)
self.connect_button.pack(pady=10)
self.pause_button = tk.Button(self, text="Pause Debugger", command=self.pause_debugger)
self.pause_button.pack(pady=10)
self.disconnect_button = tk.Button(self, text="Disconnect Debugger", command=self.disconnect_debugger)
self.disconnect_button.pack(pady=10)
def launch_browser(self):
subprocess.Popen(["launch_browser.bat"], shell=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE, text=True)
messagebox.showinfo("Info", "Browser Launched")
async def send_debugger_command(self, command):
async with websockets.connect('ws://localhost:9222/') as websocket:
await websocket.send(json.dumps(command))
response = await websocket.recv()
return json.loads(response)
async def connect_debugger_async(self):
command = {
"id": 1,
"method": "Debugger.enable"
}
response = await self.send_debugger_command(command)
messagebox.showinfo("Info", f"Connected to debugger: {response}")
def connect_debugger(self):
asyncio.run(self.connect_debugger_async())
async def pause_debugger_async(self):
command = {
"id": 2,
"method": "Debugger.pause"
}
response = await self.send_debugger_command(command)
messagebox.showinfo("Info", f"Debugger paused: {response}")
def pause_debugger(self):
asyncio.run(self.pause_debugger_async())
async def disconnect_debugger_async(self):
command = {
"id": 3,
"method": "Debugger.disable"
}
response = await self.send_debugger_command(command)
messagebox.showinfo("Info", f"Disconnected from debugger: {response}")
def disconnect_debugger(self):
asyncio.run(self.disconnect_debugger_async())
if __name__ == "__main__":
app = DebuggerControlApp()
app.mainloop()
Подробнее здесь: https://stackoverflow.com/questions/787 ... om-tkinter