Skip to content

Commit

Permalink
Retry creating websocket connection few times with Signal desktop deb…
Browse files Browse the repository at this point in the history
…ugger to avoid error out in slower computer
  • Loading branch information
laggykiller committed Nov 9, 2024
1 parent 962b08b commit ade4733
Showing 1 changed file with 10 additions and 1 deletion.
11 changes: 10 additions & 1 deletion src/sticker_convert/utils/chrome_remotedebug.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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]:
Expand Down

0 comments on commit ade4733

Please sign in to comment.