aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorTeddy Wing2023-11-12 15:48:00 +0100
committerTeddy Wing2023-11-12 15:48:00 +0100
commit032d704f74a9cec209bef6a3a97109d0874ab331 (patch)
treeccf8f066a7fe12d0a94ab03547c8854b92798760
parentff7eb76be6e8a6aa1e5ee5f3cc3efac8455e9daf (diff)
downloadextreload-032d704f74a9cec209bef6a3a97109d0874ab331.tar.bz2
main: Attempt to use Inspector.targetCrashed to reload tab
I observed during a manual test with Websocat that Manifest V3 extensions trigger an `Inspector.targetCrashed` message after reloading the extension: {"id":1,"sessionId":"21A6A75608971AEAD68DB36701F9985C","method":"Runtime.evaluate","params":{"expression":"chrome.runtime.reload()"}} {"id":1,"result":{"result":{"type":"undefined"}},"sessionId":"21A6A75608971AEAD68DB36701F9985C"} {"method":"Inspector.targetCrashed","params":{},"sessionId":"21A6A75608971AEAD68DB36701F9985C"} Here, I tried to listen for that `Inspector.targetCrashed` message and use that to trigger a tab reload. Unfortunately, that doesn't seem to work, as in my Extreload test of this code, I don't see the `Inspector.targetCrashed` message. Looks like I'll have to find a different means of reloading Manifest V3 extension tabs.
-rw-r--r--src/extension.lisp4
-rw-r--r--src/main.lisp31
2 files changed, 35 insertions, 0 deletions
diff --git a/src/extension.lisp b/src/extension.lisp
index bc75fb9..9fe258c 100644
--- a/src/extension.lisp
+++ b/src/extension.lisp
@@ -5,6 +5,10 @@
:initarg :id
:reader id
:documentation "The extension's ID.")
+ (url
+ :initarg :url
+ :reader url
+ :documentation "The DevTools Protocol target URL.")
(session-id
:initarg :session-id
:reader session-id
diff --git a/src/main.lisp b/src/main.lisp
index 3bc79c8..8ea05ab 100644
--- a/src/main.lisp
+++ b/src/main.lisp
@@ -72,6 +72,16 @@
(attach-extensions targets extension-ids)))
(when (target-attached-to-target-msg-p response)
+ (when (and (reload-current-tab config)
+ (target-attached-to-target-msg-manifest-v3-extension-p response))
+ ;; response is an extension in *extensions*
+
+ (reload-tab (json-obj-get
+ (json-obj-get response "result")
+ "sessionId"))
+
+ (return-from ws-on-message))
+
(track-service-worker-target response)
(reload-extension (json-obj-get
@@ -198,9 +208,30 @@ the target to reload the current tab."
;; Extension IDs are 32 characters long.
(+ 19 32))
+ :url (json-obj-get target-info "url")
:session-id (json-obj-get params "sessionId"))
*extensions*))))
+(defun target-attached-to-target-msg-manifest-v3-extension-p (msg)
+ "Return true if the Target.attachedToTarget message `msg` corresonds to a
+tracked Manifest V3 extension."
+ (filter
+ #'(lambda (extension)
+ (string= (json-obj-get
+ (json-obj-get
+ (json-obj-get msg "params")
+ "targetInfo")
+ "url")
+ (url extension)))
+ *extensions*))
+
+(defun manifest-v3-extension-p (extension)
+ "Return true if `extension` is in our list of tracked Manifest V3 extensions."
+ (filter
+ #'(lambda (ext)
+ ())
+ *extensions*))
+
(defun websocket-send (client data)
"Send `data` to WebSocket `client` and increment `*wg*`."
(when (debug-output *config*)