Skip to content

Library Scripts

Library Scripts offer a way to reuse code across multiple Inspections or Dashboards. Like Inspection and Dashboard scripts, Library Scripts are written in Javascript.

Library Script

Settings

Field Description
Name Unique name of the Library Script.
Description Notes about the Library Script.
Hide in Lists Whether the Library Script appears in lists. Hiding does not affect any Inspections or Dashboards using the Library Script.
Live Revision The Library Script Revision to run in Inspections or Dashboards when Developer Mode is not set.
Development Revision The Library Script Revision to run in Inspections or Dashboards when Developer Mode is set.

Revisions

Library Scripts contain a collection of Revisions. Each Revision represents one version of the script, and any Revision may be modified.

Editing

Revisions may be edited by:

  • Pressing the "Edit Revision" button on the Library Script list page. This will open the most recently created Revision for editing.
  • Pressing the "Edit Revision" button on the Library Script view page
  • Pressing the "Edit Revision" button the Library Script edit page

Once editing is complete, the changes may be saved by pressing the "Save" button in the edit overlay. Changes saved in this way will overwrite the Revision being edited. If the Revision being edited is the Published Revision, these changes will immediately take effect in any Inspections or Dashboards where this Library Script is used.

Library Script Save Button

Changes may also be saved with the "Save New Revision" button. This will create a new Revision instead of overwriting the current Revision. This is recommended if the Revision being edited is the currently published Revision to avoid disruptions to running Inspections or Dashboards.

Library Script Save Revision Button

Notes

When creating a new Revision, a note must be entered. The note should describe any changes made, and is used to create a log describing why Scripts were updated.

Library Script Note Button

Notes may be added or viewed at any point while editing a script with the Note button in the script edit overlay. This can be useful when making changes without creating a new Revision.

Library Script Note Overlay

Using Library Scripts

Library Scripts may be attached to an Inspection or Dashboard in order to make the contents of the script available to other scripts. The contents of the Library Script will be executed as soon as the Inspection or Dashboard is loaded, before any other scripts.

Limitations

As with Inspection and Dashboard scripts, Library Scripts are executed inside of a Web Worker, which limits the functionality. The full list of available Web APIs may be found at the MDN web docs. The most notable missing functionality in Web Workers is:

  • No access to the DOM.
  • No access to Local Storage, Session Storage, or cookies.
  • No access to Node APIs, like the File System.

While both Inspection and Dashboard functions are available to Library under the top level gsApi object, attempting to call Inspection functions in Dashboards or vice-versa will result in an error. It is recommended that Library Scripts do one of the following:

  • Only use Inspection functions.
  • Only use Dashboard functions.
  • Use neither Inspection nor Dashboard functions.

Autocomplete

Library Scripts may provide autocomplete code hints to the code editor using JS Doc. This can be used to provide descriptions about functions or hints about the type of parameters and return values.

For example:

/**
 * This function adds two numbers together and returns the square root.
 * @param {number} left The first number
 * @param {number} right The second number
 * @returns {number} The resulting number
 */
function addAndSqrt(left, right) {
    return Math.sqrt(left + right);
}

When calling this function, the editor will show the description of the function, and will display a red line if the parameters are not numbers.

Library Script Autocomplete

More information about providing type hints may be found in the code editor reference.

See Also