|
2 | 2 |
|
3 | 3 | Bugs happen! In this tutorial, you will learn how to debug your Adobe XD plugin.
|
4 | 4 |
|
5 |
| -## Prerequisite |
| 5 | +### Prerequisite |
6 | 6 |
|
7 | 7 | At least one plugin in your `develop` folder (you can create one using our [Quick Start tutorial](/tutorials/quick-start)).
|
8 | 8 |
|
| 9 | +### Debugging Options |
9 | 10 |
|
10 |
| -## Debugging Steps |
| 11 | +There are two ways you can debug an XD plugin: |
11 | 12 |
|
12 |
| -During development, if your plugin is misbehaving, there are few things you can do to investigate the problem. |
| 13 | +* For **quick, simple debugging**, [use the Developer Console built into XD](#quick-debugging-with-developer-console) |
| 14 | +* For **in-depth debugging**, set up your plugin for [debugging with Chrome DevTools](#debugging-with-chrome-devtools-beta) _(beta)_ |
13 | 15 |
|
14 |
| -### 1. Look for errors in the developer console |
15 | 16 |
|
16 |
| -You can see error messages your plugin may be causing with the XD developer console. |
| 17 | +## Quick debugging with Developer Console |
17 | 18 |
|
18 |
| -The developer console can be opened from the _Plugins_ menu: _Plugins > Development > Developer Console_. |
| 19 | +### 1. Check the Developer Console |
19 | 20 |
|
| 21 | +In XD, click _Plugins > Development > Developer Console_. |
20 | 22 |
|
21 |
| -### 2. Try reloading the plugins |
| 23 | +This displays information similar to what you'd find in the JS debugger's console view: |
| 24 | +* Any `console.log()` output from your plugin |
| 25 | +* Any error messages from XD due to plugin misbehavior, or failure to load a plugin |
| 26 | +* Stack traces if your code throws an uncaught exception |
22 | 27 |
|
23 |
| -You can reload all plugins in your `develop` folder from the _Plugins_ menu: _Plugins > Development > Reload Plugins_. |
| 28 | +The console output for _all_ installed XD plugins is mixed together in one single view here. |
24 | 29 |
|
25 |
| -There's also a handy keyboard shortcut: |
| 30 | +### 2. Reload your plugin after making fixes |
| 31 | + |
| 32 | +You can easily iterate on your plugin code without heaving to restart XD. Click _Plugins > Development > Reload Plugins_ to reload all plugins in your `develop` folder. This will reflect any changes in [manifest.json](/reference/structure/manifest.md) in addition to any changes to your JS code. |
| 33 | + |
| 34 | +There's also a handy keyboard shortcut to make reloading easier: |
26 | 35 |
|
27 | 36 | | Platform | Keyboard shortcut |
|
28 | 37 | | ------------- | ------------- |
|
29 | 38 | | macOS | Shift-Cmd-R |
|
30 | 39 | | Windows | Ctrl-Shift-R |
|
31 | 40 |
|
32 |
| -If there are any errors blocking the plugin from loading, they will appear in the developer console on reload: |
33 |
| - |
34 |
| - |
35 |
| - |
36 |
| -### 3. Try logging messages to the developer console |
| 41 | +If there are any errors blocking the plugin from loading, they will appear in the Developer Console on reload: |
37 | 42 |
|
38 |
| -The example code below does not appear to be creating the "Hello!" text as expected. |
| 43 | + |
39 | 44 |
|
40 |
| -Let's try adding a "start message" and an "end message" into `sayHello()` to double-check that the code is starting and running all the way to the end: |
41 | 45 |
|
42 |
| -```js |
43 |
| -function sayHello(selection) { |
44 |
| - console.log("sayHello started!"); // log a message |
| 46 | +## Debugging with Chrome DevTools _(beta)_ |
45 | 47 |
|
46 |
| - const el = new Text(); |
47 |
| - el.text = "Hello!"; |
48 |
| - el.styleRanges = [ |
49 |
| - { |
50 |
| - length: el.text.length, |
51 |
| - fill: new Color("#FFFFFF") |
52 |
| - } |
53 |
| - ]; |
| 48 | +### 1. Enable debugging on your plugin |
54 | 49 |
|
55 |
| - selection.insertionParent.addChild(el); |
56 |
| - el.moveInParentCoordinates(100, 100); |
| 50 | +Navigate to the root folder of your plugin and **create a `debug.json` file**: |
57 | 51 |
|
58 |
| - console.log("sayHello ran to the end!"); // log a message |
| 52 | +```json |
| 53 | +{ |
| 54 | + "port": 9345, |
| 55 | + "breakOnStart": false |
59 | 56 | }
|
60 | 57 | ```
|
61 | 58 |
|
62 |
| -Your `console.log` messages will appear in the developer console: |
| 59 | +* Debugging is only supported for plugins in the **`develop` folder** (not plugins installed from the Plugin Manager UI). |
| 60 | +* Specify any port number you want. |
| 61 | +* Advanced: Set `breakOnStart` to true if you want the debugger to immediately pause on the first line of code in your plugin the moment it starts loading. This is useful since you won't have a chance to open DevTools _before_ this moment to set breakpoints before that initial code runs. |
63 | 62 |
|
64 |
| - |
| 63 | +### 2. Launch Chrome DevTools |
65 | 64 |
|
66 |
| -It looks like the function is running... maybe there is another problem. |
| 65 | +1. Windows only: _before_ launching XD, open an admin command prompt and run `CheckNetIsolation LoopbackExempt -is -n="Adobe.CC.XD.adky2gkssdxte"` -- do this _each time_ you want to debug a plugin. |
| 66 | +2. Open Google Chrome and navigate to **`chrome://inspect`** _(you must use Chrome)_ |
| 67 | +3. One-time setup: ensure "Discover Network Targets" is enabled. Click the Configure button next to this and add `localhost:9345` (or whatever port number your `debug.json` file used). |
| 68 | +4. Click the "inspect" link under your plugin's ID. |
67 | 69 |
|
68 |
| - |
| 70 | +### Beta: What works, what doesn't |
69 | 71 |
|
70 |
| -Oops, the fill color set by the plugin is `#FFFFFF`, which is white: the same color as this artboard's background. |
| 72 | +Currently, you **can**... |
| 73 | +* Set breakpoints, pause & step through code, inspect the values of variables |
| 74 | +* View objects and run code in the Console view |
| 75 | +* View and edit the DOM structure of your plugin's UXP UI |
71 | 76 |
|
72 |
| -You can verify this with a `console.log` message: |
| 77 | +Most other DevTools features are not supported and may behave erratically if you attempt to use them. |
| 78 | + |
| 79 | +**Important caveats:** |
| 80 | +* XD may be unstable while debugging a plugin. Don't debug when you have important XD documents open. |
| 81 | +* Error messages are often _missing_ from the DevTools Console. Use the Developer Console within XD (see "Quick debugging" above) to be sure you are not missing any important information. |
| 82 | +* XD will be partially frozen while paused on a JS breakpoint. Don't try to interact with XD while paused. |
| 83 | +* You may see a blank white panel to the left of the DevTools UI. Ignore this, as it does nothing. |
| 84 | +* If debugging exposes any private fields and methods, do not attempt to use them. Plugins referring to private APIs will be rejected or removed from XD's plugin listing. |
| 85 | + |
| 86 | +Read the [known issues](/known-issues.md#debugging) for more details. |
73 | 87 |
|
74 |
| -```js |
75 |
| -console.log("el fill color =" + el.fill); // OUTPUT HERE |
76 |
| -``` |
77 | 88 |
|
78 | 89 | ## Next Steps
|
79 | 90 |
|
|
0 commit comments