|
| Preference Name | Value | Comment |
|---|---|---|
devtools.debugger.remote-enabled |
true |
Required |
devtools.chrome.enabled |
true |
Required |
devtools.debugger.prompt-connection |
false |
Recommended |
devtools.debugger.force-local |
false |
Set this only if you want to attach VS Code to Firefox running on a different machine (using the host property in the attach configuration) |
Then close Firefox and start it from a terminal like this:
Windows
"C:\Program Files\Mozilla Firefox\firefox.exe" -start-debugger-server
(This syntax is for a regular command prompt (cmd.exe), not PowerShell!)
OS X
/Applications/Firefox.app/Contents/MacOS/firefox -start-debugger-server
Linux
firefox -start-debugger-server
Navigate to your web application and use this launch.json configuration to attach to Firefox:
{
"version": "0.2.0",
"configurations": [
{
"name": "Launch index.html",
"type": "firefox",
"request": "attach"
}
]
}
If your application is running on a Webserver, you need to add the url and webRoot properties
to the configuration (as in the second launch configuration example above).
Skipping ("blackboxing") files
You can tell the debugger to ignore certain files while debugging: When a file is ignored, the debugger won't break in that file and will skip it when you're stepping through your code. This is the same as "black boxing" scripts in the Firefox Developer Tools.
There are two ways to enable this feature:
- You can enable/disable this for single files while debugging by choosing "Toggle skipping this file" from the context menu of a frame in the call stack.
- You can use the
skipFilesconfiguration property, which takes an array of glob patterns specifying the files to be ignored. If the URL of a file can't be mapped to a local file path, the URL will be matched against these glob patterns, otherwise the local file path will be matched. Examples for glob patterns:"${workspaceFolder}/skipThis.js"- will skip the fileskipThis.jsin the root folder of your project"**/skipThis.js"- will skip files calledskipThis.jsin any folder"**/node_modules/**"- will skip all files innode_modulesfolders anywhere in the project"http?(s):/**"- will skip files that could not be mapped to local files"**/google.com/**"- will skip files containing/google.com/in their url, in particular all files from the domaingoogle.com(that could not be mapped to local files)
Path mapping
The debug adapter needs to map the URLs of javascript files (as seen by Firefox) to local file paths
(as seen by VS Code). It creates a set of default path mappings from the configuration that work
for most projects. However, depending on the setup of your project, they may not work for you,
resulting in breakpoints being shown in gray (and Firefox not breaking on them) even after Firefox
has loaded the corresponding file. In this case, you will have to define them manually using the
pathMappings configuration property.
The easiest way to do this is through the Path Mapping Wizard: when you try to set a breakpoint during a debug session in a file that couldn't be mapped to a URL, the debug adapter will offer to automatically create a path mapping for you. If you click "Yes" it will analyze the URLs loaded by Firefox and try to find a path mapping that maps this file and as many other workspace files as possible to URLs loaded by Firefox and it will add this mapping to your debug configuration. Note that this path mapping is just a guess, so you should check if it looks plausible to you. You can also call the Path Mapping Wizard from the command palette during a debug session.
You can look at the Firefox URLs and how they are mapped to paths in the Loaded Scripts Explorer, which appears at the bottom of the debug side bar of VS Code during a debug session. By choosing "Map to local file" or "Map to local directory" from the context menu of a file or a directory, you can pick the corresponding local file or directory and a path mapping will automatically be added to your configuration.
If you specify more than one mapping, the first mappings in the list will take precedence over subsequent ones and all of them will take precedence over the default mappings.
The most common source of path mapping problems is webpack because the URLs that it generates
depend on its configuration and different URL styles are in use. If your configuration contains a
webroot property, the following mappings will be added by default in order to support most webpack
setups:
{ "url": "webpack:///~/", "path": "${webRoot}/node_modules/" }
{ "url": "webpack:///./~/", "path": "${webRoot}/node_modules/" }
{ "url": "webpack:///./", "path": "${webRoot}/" }
{ "url": "webpack:///src/", "path": "${webRoot}/src/" }
{ "url": "webpack:///node_modules/", "path": "${webRoot}/node_modules/" }
{ "url": "webpack:///webpack", "path": null }
{ "url": "webpack:///(webpack)", "path": null }
{ "url": "webpack:///pages/", "path": "${webRoot}/pages/" }
{ "url": "webpack://[name]_[chunkhash]/node_modules/", "path": "${webRoot}/node_modules/" }
{ "url": "webpack://[name]_[chunkhash]/", "path": null }
{ "url": "webpack:///", "path": "" }
When the path argument of a mapping is set to null, the corresponding URLs are prevented from
being mapped to local files. In the webpack mappings shown above this is used to specify that
URLs starting with webpack:///webpack or webpack:///(webpack) do not correspond to files in
your workspace (because they are dynamically generated by webpack). It could also be used for URLs
that dynamically generate their content on the server (e.g. PHP scripts) or if the content on the
server is different from the local file content. For these URLs the debugger will show the content
fetched from the server instead of the local file content.
You can also use * as a wildcard in the url of a pathMapping. It will match any number of
arbitrary characters except /.
Debugging WebExtensions
Here's an example configuration for WebExtension debugging:
{
"version": "0.2.0",
"configurations": [
{
"name": "Launch WebExtension",
"type": "firefox",
"request": "launch",
"reAttach": true,
"addonPath": "${workspaceFolder}"
}
]
}
The addonPath property must be the absolute path to the directory containing manifest.json.
You can reload your WebExtension using the command "Firefox: Reload add-on" (extension.firefox.reloadAddon)
from the VS Code command palette.
The WebExtension will also be reloaded when you restart the debugging session, unless you have set
reloadOnAttach to false.
You can also use the reloadOnChange property to let VS Code reload your WebExtension automatically
whenever you change a file.
You can enable/disable/toggle popup auto-hide using the commands "Firefox: Enable/Disable/Toggle
popup auto-hide" (extension.firefox.enablePopupAutohide / disablePopupAutohide / togglePopupAutohide).
Further optional configuration properties
reAttach: If you set this option totruein alaunchconfiguration, Firefox won't be terminated at the end of your debugging session and the debugger will re-attach to it at the start of your next debugging session.reloadOnAttach: This flag controls whether the web page(s) should be automatically reloaded after attaching to Firefox. The default is to reload in alaunchconfiguration with thereAttachflag set totrueand to not reload in anattachconfiguration.reloadOnChange: Automatically reload the Firefox tabs or your WebExtension whenever files change. You can specify single files, directories or glob patterns to watch for file changes and additionally specify files to be ignored. Since watching files consumes system resources, make sure that you are not watching more files than necessary. The following example will watch all javascript files in your workspace except those undernode_modules:"reloadOnChange": { "watch": [ "${workspaceFolder}/**/*.js" ], "ignore": [ "${workspaceFolder}/node_modules/**" ] }By default, the reloading will be "debounced": the debug adapter will wait until the last file change was 100 milliseconds ago before reloading. This is useful if your project uses a build system that generates multiple files - without debouncing, each file would trigger a separate reload. You can use
reloadOnChange.debounceto change the debounce time span or to disable debouncing (by setting it to0orfalse).Instead of string arrays, you can also use a single string for
watchandignoreand if you don't need to specifyignoreordebounce, you can specify thewatchvalue directly, e.g."reloadOnChange": "${workspaceFolder}/lib/*.js"
