Browse Source

Start Chrome with a temp profile by default

Using a temporary profile makes it easier for the user to have Chrome started
with the remote debugging port, as it forces a new instance of Chrome.

* indium-chrome.el (indium-chrome-use-temporary-profile): New defcustom.
(indium-launch-chrome): Start using a new profile if
`indium-chrome-use-temporary-profile' is non-nil.
* doc/Indium.texi:
* sphinx-doc/setup.rst: Documentation update.
drone
Nicolas Petton 3 years ago
parent
commit
625945483d
No known key found for this signature in database GPG Key ID: E8BCD7866AFCF978
4 changed files with 69 additions and 33 deletions
  1. +26
    -21
      doc/Indium.texi
  2. +17
    -4
      indium-chrome.el
  3. +9
    -5
      sphinx-doc/setup.rst
  4. +17
    -3
      test/unit/indium-chrome-test.el

+ 26
- 21
doc/Indium.texi View File

@ -3,7 +3,7 @@
@setfilename Indium.info
@documentencoding UTF-8
@ifinfo
@*Generated by Sphinx 1.6.6.@*
@*Generated by Sphinx 1.7.5.@*
@end ifinfo
@settitle Indium Documentation
@defindex ge
@ -21,7 +21,7 @@
@copying
@quotation
Indium 1.2.0, Sep 17, 2018
Indium 1.2.0, Nov 26, 2018
Nicolas Petton
@ -160,7 +160,7 @@ Troublehooting
@end menu
@node Table of contents,Indices and tables,Top,Top
@anchor{index table-of-contents}@anchor{1}@anchor{index indium}@anchor{2}
@anchor{index indium}@anchor{1}@anchor{index table-of-contents}@anchor{2}
@chapter Table of contents
@ -257,7 +257,7 @@ Add the following to your Emacs configuration:
@end example
@node Getting up and running,The REPL,Installation,Table of contents
@anchor{setup getting-up-and-running}@anchor{b}@anchor{setup doc}@anchor{c}@anchor{setup setup}@anchor{d}
@anchor{setup setup}@anchor{b}@anchor{setup getting-up-and-running}@anchor{c}@anchor{setup doc}@anchor{d}
@section Getting up and running
@ -357,7 +357,7 @@ Example configuration:
@end example
@node NodeJS configuration options,Starting Indium,Chrome/Chromium configuration options,Getting up and running
@anchor{setup nodejs-configuration}@anchor{10}@anchor{setup nodejs-configuration-options}@anchor{16}
@anchor{setup nodejs-configuration-options}@anchor{16}@anchor{setup nodejs-configuration}@anchor{10}
@subsection NodeJS configuration options
@ -395,7 +395,7 @@ Here is an example configuration for debugging Gulp tasks:
@end example
@node Starting Indium,NodeJS requirements,NodeJS configuration options,Getting up and running
@anchor{setup starting-indium}@anchor{17}@anchor{setup id2}@anchor{18}
@anchor{setup id2}@anchor{17}@anchor{setup starting-indium}@anchor{18}
@subsection Starting Indium
@ -414,7 +414,7 @@ specified from the configurations in the @code{.indium.json} project file.
@end itemize
@node NodeJS requirements,Chrome/Chromium requirements,Starting Indium,Getting up and running
@anchor{setup nodejs-requirements}@anchor{6}@anchor{setup id3}@anchor{19}
@anchor{setup id3}@anchor{19}@anchor{setup nodejs-requirements}@anchor{6}
@subsection NodeJS requirements
@ -440,25 +440,30 @@ If you install NodeJS using @code{nvm}, chances are that Emacs won’t have it i
@code{exec path}. A simple solution is to use the excellent exec-path-from-shell@footnote{https://github.com/purcell/exec-path-from-shell} package.
@node Chrome/Chromium requirements,,NodeJS requirements,Getting up and running
@anchor{setup chrome-requirements}@anchor{5}@anchor{setup chrome-chromium-requirements}@anchor{1a}
@anchor{setup chrome-chromium-requirements}@anchor{1a}@anchor{setup chrome-requirements}@anchor{5}
@subsection Chrome/Chromium requirements
Chrome/Chromium >= @code{60.0} is required for Indium to properly work (debugging
protocol @code{v1.2}).
Start Chrome/Chromium with the @code{--remote-debugging-port} flag like the following:
When the variable @code{indium-chrome-use-temporary-profile} is non-nil (the
default), @code{M-x indium-launch} will start a new instance of Chrome/Chromium
with the remote debugging port set up.
Otherwise, you can start Chrome/Chromium with the @code{--remote-debugging-port}
flag like the following:
@example
chromium --remote-debugging-port=9222 https://localhost:3000
@end example
Make sure that no instance of Chrome is already running, otherwise Chrome will
simply open a new tab on the existing Chrome instance, and the
@code{remote-debugging-port} will not be set.
If you start Chrome manually, make sure that no instance of Chrome is already
running, otherwise Chrome will simply open a new tab on the existing Chrome
instance, and the @code{remote-debugging-port} will not be set.
@node The REPL,Interaction in JS buffers,Getting up and running,Table of contents
@anchor{repl repl}@anchor{1b}@anchor{repl doc}@anchor{1c}@anchor{repl the-repl}@anchor{1d}
@anchor{repl the-repl}@anchor{1b}@anchor{repl repl}@anchor{1c}@anchor{repl doc}@anchor{1d}
@section The REPL
@ -475,7 +480,7 @@ simply open a new tab on the existing Chrome instance, and the
A REPL (Read Eval Print Loop) buffer is automatically open when a new Indium
connection is made (see @ref{d,,Getting up and running}).
connection is made (see @ref{b,,Getting up and running}).
@image{repl,,,,png}
@ -609,7 +614,7 @@ the current stack frame, and will be able to access local variables from the
stack, etc.
@node Interaction in JS buffers,The stepping debugger,The REPL,Table of contents
@anchor{code-evaluation interaction-in-js-buffers}@anchor{24}@anchor{code-evaluation interaction}@anchor{25}@anchor{code-evaluation doc}@anchor{26}
@anchor{code-evaluation interaction}@anchor{24}@anchor{code-evaluation doc}@anchor{25}@anchor{code-evaluation interaction-in-js-buffers}@anchor{26}
@section Interaction in JS buffers
@ -668,7 +673,7 @@ Here’s a list of available keybindings:
Press @code{C-c C-z} from any buffer with @code{indium-interaction-mode} turned on to
switch back to the REPL buffer (see @ref{1b,,The REPL}).
switch back to the REPL buffer (see @ref{1c,,The REPL}).
@node Adding and removing breakpoints,,Switching to the REPL buffer,Interaction in JS buffers
@anchor{code-evaluation adding-and-removing-breakpoints}@anchor{29}
@ -742,7 +747,7 @@ connection is made Indium will attempt to add back all breakpoints.
Since version 0.7, Indium uses sourcemap files by default.
For sourcemaps to work properly with Chrome/Chromium, make sure that a
workspace is correctly set (see @ref{d,,Getting up and running}).
workspace is correctly set (see @ref{b,,Getting up and running}).
@cartouche
@quotation Warning
@ -760,7 +765,7 @@ source-mapped. This can happen for instance when using Webpack.
@end menu
@node Overriding sourcemap paths,,,Using sourcemaps
@anchor{debugger webpack}@anchor{2e}@anchor{debugger overriding-sourcemap-paths}@anchor{2f}
@anchor{debugger overriding-sourcemap-paths}@anchor{2e}@anchor{debugger webpack}@anchor{2f}
@subsubsection Overriding sourcemap paths
@ -800,13 +805,13 @@ expression of script paths to blackbox when debugging.
Blackboxed scripts are skipped when stepping in the debugger.
@node The inspector,Troublehooting,The stepping debugger,Table of contents
@anchor{inspector inspector}@anchor{1f}@anchor{inspector the-inspector}@anchor{31}@anchor{inspector doc}@anchor{32}
@anchor{inspector the-inspector}@anchor{31}@anchor{inspector doc}@anchor{32}@anchor{inspector inspector}@anchor{1f}
@section The inspector
Indium features an object inspector that can be open on any object reference
from a REPL buffer (see @ref{1b,,The REPL}), the debugger (see @ref{2a,,The stepping debugger}), or
the result of any evaluation of JavaScript code (see @ref{25,,Interaction in JS buffers}).
from a REPL buffer (see @ref{1c,,The REPL}), the debugger (see @ref{2a,,The stepping debugger}), or
the result of any evaluation of JavaScript code (see @ref{24,,Interaction in JS buffers}).
To inspect the result of the evaluation of an expression, press @code{C-c M-i}. An
inspector buffer will pop up. You can also press @code{RET} or left click on


+ 17
- 4
indium-chrome.el View File

@ -55,18 +55,31 @@
"Default Chrome remote debugger port."
:type '(integer))
(defcustom indium-chrome-use-temporary-profile
t
"When non-nil, each invocation of the browser uses a new temporary profile."
:type '(boolean))
(defun indium-launch-chrome (conf)
"Start chrome/chromium with remote debugging enabled based on CONF settings."
(let-alist conf
(unless .url
(error "No url specified in configuration"))
(make-process :name "indium-chrome-process"
:command (list (indium-chrome--find-executable)
(format "--remote-debugging-port=%s"
(or .port indium-chrome-default-port))
.url))
:command (indium-chrome--command
(or .port indium-chrome-default-port)
.url))
(indium-client-connect (file-name-directory .projectFile) .name)))
(defun indium-chrome--command (port url)
"Return the Chrome command to be executed with PORT and URL."
(list (indium-chrome--find-executable)
(format "--remote-debugging-port=%s" port)
(if indium-chrome-use-temporary-profile
(format "--user-data-dir=%s" (make-temp-file nil t))
"")
url))
(defun indium-chrome--find-executable ()
"Find chrome executable using `indium-chrome-executable'."
(let ((executable (executable-find indium-chrome-executable)))


+ 9
- 5
sphinx-doc/setup.rst View File

@ -150,11 +150,15 @@ Chrome/Chromium requirements
Chrome/Chromium >= ``60.0`` is required for Indium to properly work (debugging
protocol ``v1.2``).
Start Chrome/Chromium with the ``--remote-debugging-port`` flag like the following:
::
When the variable ``indium-chrome-use-temporary-profile`` is non-nil (the
default), ``M-x indium-launch`` will start a new instance of Chrome/Chromium
with the remote debugging port set up.
Otherwise, you can start Chrome/Chromium with the ``--remote-debugging-port``
flag like the following: ::
chromium --remote-debugging-port=9222 https://localhost:3000
Make sure that no instance of Chrome is already running, otherwise Chrome will
simply open a new tab on the existing Chrome instance, and the
``remote-debugging-port`` will not be set.
If you start Chrome manually, make sure that no instance of Chrome is already
running, otherwise Chrome will simply open a new tab on the existing Chrome
instance, and the ``remote-debugging-port`` will not be set.

+ 17
- 3
test/unit/indium-chrome-test.el View File

@ -27,6 +27,7 @@
(require 'buttercup)
(require 'indium-chrome)
(require 'indium-client)
(require 'seq)
(describe "Chrome executable"
(it "Should try to find the executable"
@ -51,7 +52,8 @@
(name . "Web project")
(type . "chrome")
(projectFile . "/foo/bar/.indium.json")
(port . "9223"))))
(port . "9223")))
(indium-chrome-use-temporary-profile nil))
(spy-on 'indium-chrome--find-executable :and-return-value "chrome")
(spy-on 'make-process)
(spy-on 'indium-client-connect)
@ -59,7 +61,7 @@
(expect #'make-process
:to-have-been-called-with
:name "indium-chrome-process"
:command '("chrome" "--remote-debugging-port=9223" "http://localhost:9999"))))
:command '("chrome" "--remote-debugging-port=9223" "" "http://localhost:9999"))))
(it "Should connect to the chrome process"
(let ((conf '((url . "http://localhost:9999")
@ -71,7 +73,19 @@
(spy-on 'make-process)
(spy-on 'indium-client-connect)
(indium-launch-chrome conf)
(expect #'indium-client-connect :to-have-been-called))))
(expect #'indium-client-connect :to-have-been-called)))
(it "Should make a temporary profile"
(spy-on 'indium-chrome--find-executable :and-return-value "chrome")
(let* ((indium-chrome-use-temporary-profile t)
(port 9229)
(url "http://localhost:3000")
(command (indium-chrome--command port url)))
(expect (length command) :to-be 4)
(expect (seq-elt command 0) :to-equal (indium-chrome--find-executable))
(expect (seq-elt command 1) :to-equal "--remote-debugging-port=9229")
(expect (seq-elt command 2) :to-match "--user-data-dir=/tmp/.*")
(expect (seq-elt command 3) :to-equal url))))
(provide 'indium-chrome-test)
;;; indium-chrome-test.el ends here

Loading…
Cancel
Save