Bug 1874684 - Part 28: Return DateDuration from DifferenceISODateTime. r=mgaudet
[gecko.git] / remote / doc / marionette / Debugging.md
blob040db24c6e7c5f9660aa397e1e7ec24aa671f626
1 # Debugging
3 ## Redirecting the Gecko output
5 The most common way to debug Marionette, as well as chrome code in
6 general, is to use `dump()` to print a string to stdout.  In Firefox,
7 this log output normally ends up in the gecko.log file in your current
8 working directory.  With Fennec it can be inspected using `adb logcat`.
10 `mach marionette-test` takes a `--gecko-log` option which lets
11 you redirect this output stream.  This is convenient if you want to
12 “merge” the test harness output with the stdout from the browser.
13 Per Unix conventions you can use `-` (dash) to have Firefox write
14 its log to stdout instead of file:
16 ```shell
17 % ./mach marionette-test --gecko-log -
18 ```
20 It is common to use this in conjunction with an option to increase
21 the Marionette log level:
23 ```shell
24 % ./mach test --gecko-log - -vv TEST
25 ```
27 A single `-v` enables debug logging, and a double `-vv` enables
28 trace logging.
30 This debugging technique can be particularly effective when combined
31 with using [pdb] in the Python client or the JS remote debugger
32 that is described below.
34 [pdb]: https://docs.python.org/3/library/pdb.html
36 ## JavaScript debugger
38 You can attach the [Browser Toolbox] JavaScript debugger to the
39 Marionette server using the `--jsdebugger` flag.  This enables you
40 to introspect and set breakpoints in Gecko chrome code, which is a
41 more powerful debugging technique than using `dump()` or `console.log()`.
43 To automatically open the JS debugger for `Mn` tests:
45 ```shell
46 % ./mach marionette-test --jsdebugger
47 ```
49 It will prompt you when to start to allow you time to set your
50 breakpoints.  It will also prompt you between each test.
52 You can also use the `debugger;` statement anywhere in chrome code
53 to add a breakpoint.  In this example, a breakpoint will be added
54 whenever the `WebDriver:GetPageSource` command is called:
56 ```javascript
57     GeckoDriver.prototype.getPageSource = async function() {
58       debugger;
59       …
60     }
61 ```
63 To be prompted at the start of the test run or between tests,
64 you can set the `marionette.debugging.clicktostart` preference to
65 `true` this way:
67 ```shell
68 % ./mach marionette-test --setpref='marionette.debugging.clicktostart=true' --jsdebugger
69 ```
71 For reference, below is the list of preferences that enables the
72 chrome debugger for Marionette.  These are all set implicitly when
73 `--jsdebugger` is passed to mach.  In non-official builds, which
74 are the default when built using `./mach build`, you will find that
75 the chrome debugger won’t prompt for connection and will allow
76 remote connections.
78 * `devtools.browsertoolbox.panel` -> `jsdebugger`
80   Selects the Debugger panel by default.
82 * `devtools.chrome.enabled` → true
84   Enables debugging of chrome code.
86 * `devtools.debugger.prompt-connection` → false
88   Controls the remote connection prompt.  Note that this will
89   automatically expose your Firefox instance to localhost.
91 * `devtools.debugger.remote-enabled` → true
93   Allows a remote debugger to connect, which is necessary for
94   debugging chrome code.
96 [Browser Toolbox]: /devtools-user/browser_toolbox/index.rst