diff options
| -rw-r--r-- | extreload.asd | 1 | ||||
| -rw-r--r-- | scratch.lisp | 20 | ||||
| -rw-r--r-- | src/devtools-protocol.lisp | 6 | ||||
| -rw-r--r-- | src/extension.lisp | 13 | ||||
| -rw-r--r-- | src/main.lisp | 46 | 
5 files changed, 83 insertions, 3 deletions
| diff --git a/extreload.asd b/extreload.asd index d0c943f..6a037e5 100644 --- a/extreload.asd +++ b/extreload.asd @@ -37,6 +37,7 @@                               (:file "config")                               (:file "option")                               (:file "call-id") +                             (:file "extension")                               (:file "devtools-protocol")                               (:file "main")))) diff --git a/scratch.lisp b/scratch.lisp new file mode 100644 index 0000000..7d64977 --- /dev/null +++ b/scratch.lisp @@ -0,0 +1,20 @@ +(ql:quickload "extreload") + +(defvar extreload::*config* +    (extreload::make-config :socket-url "ws://127.0.0.1:55755/devtools/browser/4536efdf-6ddf-40b6-9a16-258a1935d866"  +                 :reload-current-tab t +                 :debug-output t +                 :extension-ids '("imcibeelfmccdpnnlemllnepgbfdbkgo"))   +  ) + + +(replace +  "chrome-extension://imcibeelfmccdpnnlemllnepgbfdbkgo/background.bundle.js" +  "" +  :end1 20) +;chrome-extension://imcibeelfmccdpnnlemllnepgbfdbkgo/background.bundle.js + +(subseq +  "chrome-extension://imcibeelfmccdpnnlemllnepgbfdbkgo/background.bundle.js" +  19 +  (+ 19 32)) diff --git a/src/devtools-protocol.lisp b/src/devtools-protocol.lisp index 6e60f69..1d183bc 100644 --- a/src/devtools-protocol.lisp +++ b/src/devtools-protocol.lisp @@ -56,6 +56,12 @@    "Returns true if `message` describes a runtime exception"    (jsown:keyp (json-obj-get message "result") "exceptionDetails")) +(defun inspector-target-crashed-msg-p (message) +  "Returns true if `message` describes a target crashed" +  (equal +    (json-obj-get message "method") +    "Inspector.targetCrashed")) +  (defun parse-get-targets-response (response)    "Parses a list of target info objects from the response to `Target.getTargets`."    (let* ((result (json-obj-get response "result")) diff --git a/src/extension.lisp b/src/extension.lisp new file mode 100644 index 0000000..bc75fb9 --- /dev/null +++ b/src/extension.lisp @@ -0,0 +1,13 @@ +(in-package :extreload) + +(defclass extension () +  ((id +     :initarg :id +     :reader id +     :documentation "The extension's ID.") +   (session-id +     :initarg :session-id +     :reader session-id +     :documentation "A DevTools Protocol session ID.")) + +  (:documentation "An extension.")) diff --git a/src/main.lisp b/src/main.lisp index 79d0a4a..3bc79c8 100644 --- a/src/main.lisp +++ b/src/main.lisp @@ -23,6 +23,8 @@    "DevTools Protocol call ID.")  (defvar *devtools-secondary-call-id* (make-instance 'call-id)    "DevTools Protocol call ID used for messages to individual target sessions.") +(defvar *extensions* '() +  "TODO")  (defconstant +timeout-seconds+ 5    "Global timeout. The program will exit at the end of this delay.") @@ -70,9 +72,27 @@          (attach-extensions targets extension-ids)))      (when (target-attached-to-target-msg-p response) -        (reload-extension (json-obj-get -                            (json-obj-get response "params") -                            "sessionId"))) +      (track-service-worker-target response) + +      (reload-extension (json-obj-get +                          (json-obj-get response "params") +                          "sessionId"))) + +    ; (format t "EXTENSIONS: ~a~%" *extensions*) + +    (when (and (reload-current-tab config) +               (inspector-target-crashed-msg-p response)) +      ;; Attach to target again +      ;; then somehow reload the tab +      ;; And need to only do this for MV3 extensions + +      ;; Loop through *extensions*, if sessionId matches, then send attach message to extension +      ;; Need to get new targets, and attach to all MV3 extensions again +      (websocket-send +        (ws-client *config*) +        (target-get-targets-msg +          (next-call-id *devtools-root-call-id*))) +      )      (when (and (reload-current-tab config)                 (runtime-evaluate-msg-p response)) @@ -161,6 +181,26 @@ the target to reload the current tab."      (filter #'extensionp targets))) +(defun track-service-worker-target (target) +  "TODO" +  (let* ((params (json-obj-get target "params")) +         (target-info (json-obj-get params "targetInfo"))) + +    (when (string= (json-obj-get target-info "type") +                   "service_worker") +      (push +        (make-instance 'extension +                       :id (subseq +                             (json-obj-get target-info "url") + +                             ;; Remove "chrome-extension://". +                             19 + +                             ;; Extension IDs are 32 characters long. +                             (+ 19 32)) +                       :session-id (json-obj-get params "sessionId")) +        *extensions*)))) +  (defun websocket-send (client data)    "Send `data` to WebSocket `client` and increment `*wg*`."    (when (debug-output *config*) | 
