A JavaScript development environment for Emacs https://indium.readthedocs.io
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 

101 lines
3.3 KiB

  1. ;;; indium-chrome.el --- Chrom{e|ium} support for indium -*- lexical-binding: t; -*-
  2. ;; Copyright (C) 2016-2018 Nicolas Petton
  3. ;; Author: Nicolas Petton <nicolas@petton.fr>
  4. ;; Keywords: tools, javascript
  5. ;; This program is free software; you can redistribute it and/or modify
  6. ;; it under the terms of the GNU General Public License as published by
  7. ;; the Free Software Foundation, either version 3 of the License, or
  8. ;; (at your option) any later version.
  9. ;; This program is distributed in the hope that it will be useful,
  10. ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  12. ;; GNU General Public License for more details.
  13. ;; You should have received a copy of the GNU General Public License
  14. ;; along with this program. If not, see <http://www.gnu.org/licenses/>.
  15. ;;; Commentary:
  16. ;; Handle indium connections to Chrom{e|ium} using the v8 backend.
  17. ;;; Code:
  18. (require 'url)
  19. (require 'json)
  20. (require 'map)
  21. (require 'seq)
  22. (declare-function indium-client-connect "indium-client.el")
  23. (defgroup indium-chrome nil
  24. "Chrome interaction."
  25. :prefix "indium-chrome-"
  26. :group 'indium)
  27. (defun indium-chrome--default-executable ()
  28. "Return a default executable based on the OS."
  29. (cond ((string-equal system-type "darwin")
  30. "/Applications/Google Chrome.app/Contents/MacOS/Google Chrome")
  31. ((string-equal system-type "windows-nt")
  32. "C:/Program Files (x86)/Google/Chrome/Application/chrome.exe")
  33. (t "chromium")))
  34. (defcustom indium-chrome-executable
  35. (indium-chrome--default-executable)
  36. "Chrome executable."
  37. :type '(file))
  38. (defcustom indium-chrome-default-port
  39. 9222
  40. "Default Chrome remote debugger port."
  41. :type '(integer))
  42. (defcustom indium-chrome-use-temporary-profile
  43. t
  44. "When non-nil, each invocation of the browser uses a temporary profile.
  45. The temporary profile can be set with `indium-chrome-data-dir'."
  46. :type '(boolean))
  47. (defvar indium-chrome--default-data-dir (expand-file-name "indium-chrome-profile"
  48. user-emacs-directory)
  49. "Default directory used as Chrome data directory.")
  50. (defvar indium-chrome-data-dir
  51. (make-directory indium-chrome--default-data-dir t)
  52. "Chrome profile directory used by Indium.")
  53. (defun indium-launch-chrome (conf)
  54. "Start chrome/chromium with remote debugging enabled based on CONF settings."
  55. (let-alist conf
  56. (unless .url
  57. (error "No url specified in configuration"))
  58. (make-process :name "indium-chrome-process"
  59. :command (indium-chrome--command
  60. (or .port indium-chrome-default-port)
  61. .url))
  62. (indium-client-connect (file-name-directory .projectFile) .name)))
  63. (defun indium-chrome--command (port url)
  64. "Return the Chrome command to be executed with PORT and URL."
  65. (list (indium-chrome--find-executable)
  66. (format "--remote-debugging-port=%s" port)
  67. (if indium-chrome-use-temporary-profile
  68. (format "--user-data-dir=%s" indium-chrome-data-dir)
  69. "")
  70. url))
  71. (defun indium-chrome--find-executable ()
  72. "Find chrome executable using `indium-chrome-executable'."
  73. (let ((executable (executable-find indium-chrome-executable)))
  74. (unless executable
  75. (user-error "Cannot find chrome/chromium binary (%s) in PATH" indium-chrome-executable))
  76. executable))
  77. (provide 'indium-chrome)
  78. ;;; indium-chrome.el ends here