Skip to content

Instantly share code, notes, and snippets.

@takumikinjo
Created December 17, 2011 08:15
Show Gist options
  • Save takumikinjo/1489644 to your computer and use it in GitHub Desktop.
Save takumikinjo/1489644 to your computer and use it in GitHub Desktop.
ojagnaha1217
;; /Applications/Google\ Chrome.app/Contents/MacOS/Google\ Chrome --remote-shell-port=9999
;; telnet localhost 9999
;; ChromeDevToolsHandshake
;; Destination:
;; Tool:DevToolsService
;; Content-Length:66
;;
;; {"command":"list_tabs","data":[[2,"chrome://newtab/"]],"result":0}
(setq chrome-dev-tools-protocol-buffer nil)
(defun chrome-dev-tools-protocol-open (port &optional host)
(or (and (buffer-live-p chrome-dev-tools-protocol-buffer)
(and (get-buffer-process chrome-dev-tools-protocol-buffer) chrome-dev-tools-protocol-buffer))
(setq chrome-dev-tools-protocol-buffer
(let ((buf (make-comint "chrome-dev-tools-protocol-buffer" (cons (or host "localhost") port))))
(send-string (get-buffer-process buf) "ChromeDevToolsHandshake\r\n")
buf))))
;; Run google-chrome with an option: --remote-shell-port=9999 as following
;;
(chrome-dev-tools-protocol-open 9999)
(defun chrome-dev-tools-protocol-dev-tools-service-send (s)
(comint-send-string
(get-buffer-process chrome-dev-tools-protocol-buffer)
(format "Content-Length:%d\r\nTool:DevToolsService\r\n\r\n%s\r\n" (string-bytes s) s)))
(defun chrome-dev-tools-protocol-v8debugger-send (destination s)
(comint-send-string
(get-buffer-process chrome-dev-tools-protocol-buffer)
(format "Content-Length:%d\r\nTool:V8Debugger\r\nDestination:%d\r\n\r\n%s\r\n" (string-bytes s) destination s)))
(defun chrome-dev-tools-protocol-v8debugger-send-javascript (destination js)
(chrome-dev-tools-protocol-v8debugger-send destination (format "{\"data\": \"%s\", \"command\": \"evaluate_javascript\"}" js)))
;; find tab id
(chrome-dev-tools-protocol-dev-tools-service-send "{\"command\": \"list_tabs\"}")
;; set tab id
(setq d 2)
;; write console
(chrome-dev-tools-protocol-v8debugger-send-javascript d "console.log('hello')")
;; gonyo gonyo-
(let ((buf (let ((coffee-code "alert 'hello'")
(temp-path (make-temp-file "tmp")))
(let* ((coffee-path (concat temp-path ".coffee"))
(buf (find-file-noselect coffee-path)))
(with-current-buffer buf
(insert coffee-code)
(save-buffer))
(shell-command-to-string (concat "coffee -c " coffee-path)))
(with-current-buffer (find-file-noselect (concat temp-path ".js"))
(buffer-string)))))
(chrome-dev-tools-protocol-v8debugger-send-javascript d buf))
(defun foobar (coffee-code)
"gonyo gonyo-"
(let ((buf
(let ((temp-path (make-temp-file "tmp")))
(let* ((coffee-path (concat temp-path ".coffee"))
(buf (find-file-noselect coffee-path)))
(with-current-buffer buf
(insert coffee-code)
(save-buffer))
(shell-command-to-string (concat "coffee -c " coffee-path)))
(with-current-buffer (find-file-noselect (concat temp-path ".js"))
(buffer-string)))))
(chrome-dev-tools-protocol-v8debugger-send-javascript d buf)))
(foobar "
square = (x) -> x * x
console.log 'hello'
alert 'hello ' + square(2)
")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment