Newer Version Available

This content describes an older version of this product. View Latest

Evaluate JavaScript Code Compatibility with Locker Service

Ensure that your code is compatible with Locker Service by running the code with Locker Service enabled. Run the code a second time with Locker Service disabled to see if any errors are due to Locker Service restrictions.

Let's look at an example that uses a prohibited DOM API.

  1. Paste this code into the console.
    1var controller = new AbortController();
    2controller;
  2. Click Evaluate.

    Note the error in the LOCKER ON column of the results window.

    1TypeError: AbortController is not a constructor

    You get this error because AbortController is an experimental interface in the DOM API and is not allowed by Locker Service.

    The LOCKER OFF column shows – (dash) as this column isn't relevant when the Locker toggle is enabled.

  3. Click the Locker toggle to disable Locker Service.
  4. Click Evaluate to rerun the code sample with Locker Service disabled.

    The second row of the results window shows there's no longer an error when Locker Service is disabled. The LOCKER OFF column shows [object AbortController], which is the return value of the sample code.

    Locker Console evaluate results

Use the Locker Service API Viewer to see the DOM APIs exposed by Locker Service versus the standard DOM APIs for the most complex wrappers: SecureDocument, SecureElement, and SecureWindow.