From ade4733d0fbd60d8fac2d0a6360f5499585e50ce Mon Sep 17 00:00:00 2001 From: laggykiller Date: Sat, 9 Nov 2024 18:58:13 +0800 Subject: [PATCH] Retry creating websocket connection few times with Signal desktop debugger to avoid error out in slower computer --- src/sticker_convert/utils/chrome_remotedebug.py | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/src/sticker_convert/utils/chrome_remotedebug.py b/src/sticker_convert/utils/chrome_remotedebug.py index 77fa9de..e32bc15 100644 --- a/src/sticker_convert/utils/chrome_remotedebug.py +++ b/src/sticker_convert/utils/chrome_remotedebug.py @@ -84,7 +84,7 @@ def get_chrome_path() -> Optional[str]: def connect(self): self.cmd_id = 1 r = None - for _ in range(3): + for _ in range(5): try: r = requests.get(f"http://localhost:{self.port}/json") break @@ -95,6 +95,15 @@ def connect(self): raise RuntimeError("Cannot connect to chrome debugging port") targets = json.loads(r.text) + for _ in range(5): + if len(targets) == 0: + time.sleep(1) + else: + break + + if len(targets) == 0: + raise RuntimeError("Cannot create websocket connection with debugger") + self.ws = websocket.create_connection(targets[0]["webSocketDebuggerUrl"]) # type: ignore def send_cmd(self, command: Dict[Any, Any]) -> Union[str, bytes]: