From 2a46357cb58d740611fc3ed1f7d58b2a76bce602 Mon Sep 17 00:00:00 2001 From: Teddy Wing Date: Sun, 21 Feb 2021 23:01:51 +0100 Subject: When `chrome.tabs.reload()` errors, double decrement the wait group We added an extra increment to the wait group in the `reload-tab` function because when the `chrome.tabs.reload()` message succeeds, we receive two response messages for a single one sent. When an error comes back from the message, however, only one message is received instead of two. We must thus decrement the wait group an extra time to account for the lack of a second response message. Here's what the message sequence looks like: # Sending: {"id":2,"sessionId":"C67B0BF214B28E1233277D01B897438E","method":"Runtime.evaluate","params":{"expression":"chrome.tabs.reload()"}} Response: (OBJ (id . 2) (result OBJ (result OBJ (type . object) (subtype . error) (className . TypeError) (description . TypeError: Cannot read property 'reload' of undefined at :1:13) (objectId . 1547982045888266898.197.11)) (exceptionDetails OBJ (exceptionId . 15) (text . Uncaught) (lineNumber . 0) (columnNumber . 12) (scriptId . 1569) (exception OBJ (type . object) (subtype . error) (className . TypeError) (description . TypeError: Cannot read property 'reload' of undefined at :1:13) (objectId . 1547982045888266898.197.12)))) (sessionId . C67B0BF214B28E1233277D01B897438E)) # Sending: {"id":2,"sessionId":"C67B0BF214B28E1233277D01B897438E","method":"Runtime.evaluate","params":{"expression":"chrome.tabs.reload()"}} Response: (OBJ (id . 2) (result OBJ (result OBJ (type . object) (subtype . error) (className . TypeError) (description . TypeError: Cannot read property 'reload' of undefined at :1:13) (objectId . 1547982045888266898.197.13)) (exceptionDetails OBJ (exceptionId . 16) (text . Uncaught) (lineNumber . 0) (columnNumber . 12) (scriptId . 1569) (exception OBJ (type . object) (subtype . error) (className . TypeError) (description . TypeError: Cannot read property 'reload' of undefined at :1:13) (objectId . 1547982045888266898.197.14)))) (sessionId . C67B0BF214B28E1233277D01B897438E)) # Sending: {"id":2,"sessionId":"C67B0BF214B28E1233277D01B897438E","method":"Runtime.evaluate","params":{"expression":"chrome.tabs.reload()"}} Response: (OBJ (id . 2) (result OBJ (result OBJ (type . undefined))) (sessionId . C67B0BF214B28E1233277D01B897438E)) # --- l/src/main.lisp | 5 +++++ 1 file changed, 5 insertions(+) (limited to 'l/src/main.lisp') diff --git a/l/src/main.lisp b/l/src/main.lisp index 81f05d6..f6b7d07 100644 --- a/l/src/main.lisp +++ b/l/src/main.lisp @@ -78,6 +78,11 @@ ;; Failed to reload tab. (when (jsown:keyp (json-obj-get response "result") "exceptionDetails") + ;; `reload-tab` adds an extra increment to the wait group. If the call + ;; fails, we only receive one message instead of two, so the wait group + ;; must be decremented to match. + (wait-group:done *wg*) + (reload-tab (json-obj-get response "sessionId"))) (wait-group:done *wg*))) -- cgit v1.2.3