Debugging JavaScript in Firefox
With RubyMine, you can debug your client-side JavaScript in Firefox, version 36 and higher, using the Firefox remote debugging functionality. However it is strongly recommended that you use Chrome or any other browser of the Chrome family for the following reasons:
- RubyMine does not support source maps during a debugging session in FireFox, which blocks debugging of compressed or machine-generated JavaScript.
- When debugging in Firefox, you cannot preview the changes to your HTML, CSS, or JavaScript code on the fly - this functionality, known as Live Edit, is supported through the JetBrains Chrome extension and therefore is available only in Google Chrome.
You can debug an application running on the RubyMine built-in web server or on an external server.
Enabling Firefox remote debugging
- Open your Firefox browser, then open .
- In the Development Tools pane that opens, click Toolbox Options on the toolbar, and select the Enable remote debugging checkbox under Advanced Settings.
- Choose
listen <port number>
. You can set any port number, however it is recommended that you use 6000 and higher. Later you will specify this port number in the run configuration. . In the console that opens at the bottom of the browser, type
Debugging an application
- Set the breakpoints in the JavaScript code, as required.
- Create a debug configuration of the type Firefox Remote:
Choose from the main menu, click on the toolbar and select Firefox Remote from the pop-up list. - In the Run/Debug Configuration: Firefox Remote dialog box that opens, type
localhost
in the Host field. In the Port field, type the port that you specified when you enabled remote debugging in Firefox. The default value is6000
. - Open your application in Firefox. The browser shows the application after the code execution, that is, the breakpoints you set have no effect yet.
- Choose the newly created configuration in the Select run/debug configuration drop-down list on the toolbar and click Debug .
- In the dialog that opens, click OK to allow incoming connection from the browser.
- Refresh the application page in the browser: the page shows the results of code execution up to the first breakpoint.
- In the Debug tool window, proceed as usual: step through the program, stop and resume the program execution, examine it when suspended, view actual HTML DOM, etc.
Example
Suppose you have a simple application that consists of two files: index.html and index.js file, where index.html references index.js. This example shows how you can debug the application when it is running on the RubyMine built-in server.
To start debugging
- Set the breakpoints in index.js.
- Create a FireFox Remote debug configuration, type
localhost
and6000
in the Host and Port fields respectively: - Open index.html in the editor, choose Open in browser on the context menu, and then choose Firefox from the list: The browser opens showing the application running on the RubyMine port (currently
63345
): - Select the index_firefox_remote configuration from the drop-down list on the toolbar and click Debug : Click OK in the Incoming Connection dialog that opens: Refresh the application page in the browser.
Last modified: 1 August 2018