Skip to content

Debugging Custom Gizmos

A Custom Gizmo runs in the user's browser, in a sandboxed iframe inside the task page. The browser developer tools work inside that iframe. This page shows where to look, then lists each symptom the way a user or the console shows it, with its cause and fix.

At a glance

  • Main tool The browser developer tools (F12): Console, Sources and Network
  • Run commands inside the gizmo Pick the gizmo's frame in the console's context selector
  • Fast loop The editor preview runs your code with default inputs
  • Most failures Missing OnReceiveConfig, a CSP block, a CORS block, or a missing permission

Summary

Symptom Group
Failed to load Custom Gizmo Loading
Error reloading DOM elements Loading
The gizmo stays blank or shows Loading Loading
Inputs are empty or show the default Loading
Project files fail with HTTP 401 after the task sits open Loading
A missing permission blocks the task page Loading
Content Security Policy blocks a request Blocked requests
CORS policy blocks a request Blocked requests
A gizmo.API call fails Blocked requests
The task proceeds when the gizmo said no Task behavior
The gizmo lost the user's work Task behavior
Configure Gizmo shows no fields Task behavior
The next task is created unassigned Task behavior

Tools

  • Console (F12) console.log, console.warn and console.error from your gizmo appear in the browser console with the messages of the task page. To run commands inside the gizmo, for example gizmo.Config.GetString("work-item-id"), pick the gizmo's frame in the console's context selector (the "top" drop-down in Chromium browsers).
  • Sources Your project files appear in the Sources panel under long signed URLs. Set breakpoints there, or add a debugger; statement to main.js.
  • Network Shows each project file load and each call to your own services, with request and response headers. Use it to check Origin: null and the CORS headers.
  • Editor preview The Custom Gizmos editor runs your gizmo next to the code. It has no inputs, so gizmo.Config returns defaults. Events, BlockTask and published results do nothing in the preview. gizmo.API works and runs as you.

Messages the runtime writes to the console:

Console message Meaning
Successfully published Gizmo result PublishResult() reached the task
Modifying url from "./x" to "..." in isolated iframe A project path was rewritten to a signed file URL. Normal.
API Call to /api/... The task page made a gizmo.API call for the gizmo. Normal.
Invalid URL / Invalid Controller / Invalid Endpoint A gizmo.API call named a group or action that does not exist
Exception when trying to call Custom Gizmo CanProceedAsync, resolving as true Your CheckIfCanProceed failed, and the task was allowed to proceed
Isolation test '...' failed / Page Not Isolated! The gizmo is not running in the sandbox. Your code does not run.

Loading

Failed to load Custom Gizmo

  • Message Failed to load Custom Gizmo
  • Cause The first file (index.html) did not load. The user lacks Use Custom Gizmos, or the layout points at a project that was deleted or replaced by an import.
  • Fix Grant Use Custom Gizmos. Re-add the gizmo to the layout.
  • See Project Structure

Error reloading DOM elements

  • Message Error Reloading DOM Elements
  • Cause A script, stylesheet or image in index.html did not finish loading within about 10 seconds, usually a CDN that is not in whitelist.txt.
  • Fix Check the Network panel for a failed or blocked request. Add the origin to whitelist.txt, or upload the file to the project.
  • See Chart Task Values with a CDN Library

The gizmo stays blank or shows Loading

  • Symptom The gizmo stays blank or shows Loading....
  • Cause OnShow never ran. Either gizmo.OnReceiveConfig(...) is not registered or it threw (OnShow waits for it), or main.js threw at load time, or a <script> tag uses a path with no prefix, such as src="main.js".
  • Fix Register OnReceiveConfig, even empty. Read the console error and its line number. Use src="{project}/main.js".
  • See API Reference

Inputs are empty or show the default

  • Cause The key is not aliased in the layout; or the Start A Task step has no Input Mapping for it, or maps the wrong bucket or key; or the code reads gizmo.Config before OnReceiveConfig ran; or the value was read with the wrong type (task inputs are text).
  • Fix In Configure Gizmo, tick Use Value from Input and check the Input Name. Check the mapping. Read gizmo.Config in OnShow with GetString, and convert in code.
  • See Getting Started

Project files fail with HTTP 401 after the task sits open

  • Cause The signed links that load project files expire after 5 minutes (tenant setting CustomGizmosHMACTimeoutInMinutes).
  • Not affected The files index.html lists load at start and are not affected. A project file your code loads later, for example an image added after a click, fails once the gizmo has been open longer than that.
  • Fix Load every project file when the gizmo starts. Moving to another task page and back reloads the gizmo with new links.
  • See Security and Sandboxing

A missing permission blocks the task page

  • Message You are missing the "..." permission required by the ... Gizmo
  • Cause A gizmo on the page declares a permission the user does not have. The whole task page refuses to load, not only the gizmo.
  • Fix Grant the permission, or remove the declaration if the gizmo no longer needs it.
  • After a change After you change DeclarePermissions, remove the gizmo from the layout and add it again; the layout keeps the list it copied when you added the gizmo.
  • See API Reference

Blocked requests

Content Security Policy blocks a request

  • Message Refused to connect to '...' because it violates the following Content Security Policy directive
  • Cause The content security policy allows only the gizmo's own files and the origins in whitelist.txt, and blocks inline scripts and eval.
  • Fix Find the directive in the message, then use the table below.
  • See Security and Sandboxing

The console can also report a script, an inline script, an image or unsafe-eval:

Typical CSP messages
Refused to connect to 'https://api.example.com/...' because it violates the following Content Security Policy directive: "connect-src 'self' ..."
Refused to load the script 'https://cdn.example.com/lib.js' because it violates the following Content Security Policy directive: "script-src 'self' ..."
Refused to execute inline script because it violates the following Content Security Policy directive: "script-src 'self' ..."
Refused to evaluate a string as JavaScript because 'unsafe-eval' is not an allowed source of script
Directive in the message Fix
connect-src Add the origin (https://api.example.com) to whitelist.txt
script-src for a URL Add the CDN origin to whitelist.txt
script-src, inline script Move the code from the <script> block or onclick attribute into a .js file
unsafe-eval The code uses eval or new Function. Use a library build that does not.
img-src for data: Add data: to whitelist.txt, or serve the image as a project file

Reload after you change the whitelist

The gizmo reads whitelist.txt when it loads. Reload the task after you change it.

CORS policy blocks a request

  • Message has been blocked by CORS policy from origin 'null'
  • Cause The sandbox gives the gizmo an opaque origin, so every request carries Origin: null, and your server does not allow it.
  • Fix Return Access-Control-Allow-Origin: * (or null) on the response, and answer the OPTIONS preflight when the request has a JSON body or custom headers. Cookies are never sent.
  • See Look Up a Record in Your Own System
Typical CORS message
Access to fetch at 'https://api.example.com/...' from origin 'null' has been blocked by CORS policy: No 'Access-Control-Allow-Origin' header is present on the requested resource.

A gizmo.API call fails

  • Symptom A gizmo.API call fails, or returns Success: false.
  • Cause The server checks the signed-in user's features for every call, and declaring a permission does not grant it; or the body uses the wrong property name or case; or the group or action name does not exist (Invalid Controller, Invalid Endpoint).
  • Fix Grant the feature to the user. Check the request shape in the API reference (for example { WorkItemId: "..." }). Handle both a rejected Promise and Success: false.
  • See API Reference

Task behavior

The task proceeds when the gizmo said no

  • Cause CheckIfCanProceed threw or its Promise rejected, and the platform then lets the task proceed; or the gizmo is on another page than the one the user completes from.
  • Fix Wrap the callback body in try/catch and return false on error. Put blocking gizmos on the last page.
  • See Checklist That Blocks Task Completion

The gizmo lost the user's work

  • Cause The iframe is destroyed when the gizmo is hidden and loaded fresh when it is shown. In-memory state is gone, and localStorage is blocked by the sandbox.
  • Fix Publish progress as a result, and place gizmos that collect work on the page where the user finishes.
  • See Introduction

Configure Gizmo shows no fields

  • Cause gizmo.json has an empty schema. The editor writes it by running the gizmo when you save main.js; if main.js throws at load time, the schema is empty.
  • Fix Fix the error, save main.js, check gizmo.json, then add the gizmo to the layout again.
  • See Project Structure

The next task is created unassigned

  • Cause The user token mapped to the layout's assign-to input belongs to someone who is not in the task's assignment pool, or who has no Run permission on the workflow.
  • Fix Add the person to the pool, or pick an eligible person.
  • See Pick an Assignee from a Live Directory