Debugging Client Scripts

Client scripts are executed on the client browser based on how they are deployed. To debug a client script, use the debugging tools available on your browser. SuiteScript supports several browsers:

Each browser includes its own debugging tools. The following table includes links to documentation for each browser.

Browser

Documentation Link

Google Chrome

https://developers.google.com/web/tools/chrome-devtools/javascript

Mozilla Firefox

https://developer.mozilla.org/en-US/docs/Tools/Debugger

Microsoft Edge

https://docs.microsoft.com/en-us/microsoft-edge/devtools-guide/debugger

Apple Safari

https://developer.apple.com/library/archive/documentation/AppleApplications/Conceptual/Safari_Developer_Guide/Debugger/Debugger.html and https://support.apple.com/guide/safari-developer/welcome/mac

Client scripts (both form- and record-level) should be tested on the form/record they run against. See SuiteScript 2.x Client Script Entry Points and API for more information about triggering a client script. Also see Record-Level and Form-Level Script Deployments for more information about deploying a client script.

All browsers support common actions within their debugging environments. These actions including stepping through or over code, setting breakpoints, and pausing/resume execution.

Important:

To debug a client script, the script MUST include a ‘debugger;’ statement. Place the ‘debugger;’ statement near the top of the script so that the debugger is invoked immediately when the script is triggered. Execution will stop when the statement is reached, allowing you to examine script properties and variables using the debugging tools in your browser.

To debug a SuiteScript client script:

  1. Create, upload and deploy your client script. Note that to debug a client script, it must include a 'debugger;' statement. For example:

                    debugger;
    var k = 1;
    k *= (k + 9); 
    console.log(k); 
    
                  
  2. Get ready to perform the action to trigger your client script. For example, if your client script trigger (entry point) is saveRecord on the Purchase Order record, open a new purchase order in NetSuite, enter your data, but do not click Save.

  3. Access the debugger in your browser (before triggering the script):

    • Enter CTRL+SHIFT+I in Chrome

    • Enter CTRL+SHIFT+I in Firefox

    • Enter CTRL+OPTION+I in Safari

    Note:

    If you access the browser debugger before you are ready to trigger your script, the debugger may pause at every action you perform in the browser causing unnecessary and premature interaction with the debugger.

  4. When the debugger is open, click Save on the purchase order (in this example). The debugger will pause the execution of your script at the location of the ‘ debugger;‘ statement. You can now use the debugger tools in your browser to step through the code, look at values, set breakpoints, etc. Refer to the documentation for your browser for more information.

    When debugging client scripts, some scripts might be minified. Minified scripts have all unnecessary characters removed, including white space and new line characters. You can use your browser debug tools to de-minify the script. This is typically done using the { } button. See the documentation for your browser for more information.

  5. When you are done using the debugger, it can be closed. Your NetSuite page will remain displayed and you can continue using NetSuite.

For additional information about working with client scripts, see SuiteScript 2.x Client Script Entry Points and API and Record-Level and Form-Level Script Deployments.

Related Topics

SuiteScript Debugger
Debugging Overview
Debugging SuiteScript 1.0 and SuiteScript 2.0 Scripts
Debugging SuiteScript 2.1 Scripts
Script Debugger Metering and Permissions

General Notices