The API environment
If you're used to writing JavaScript for web pages or Node.js servers, there are some things to know about the JavaScript environment when creating XD plugins.
Not a browser and not Node.js
While it may feel like it, the XD plugin API environment is not a browser, nor is it Node.js. This means that you shouldn't make assumptions about what APIs are available based on your experience in other JavaScript environments.
However, we do follow standards for API surfaces where appropriate. For example, you'll find our implementation of XMLHttpRequest
to work as you would expect.
In some cases, we follow standards, but only support a subset of features you might expect in a browser. As an example, see our document on CSS support.
Accessing global APIs
Supported APIs that you would expect as window globals in other enviroments are also available as globals in XD. Examples include XMLHttpRequest
, fetch
, WebSocket
, document
, and more.
Example:
Copied to your clipboardlet req = new XMLHttpRequest();
APIs that are specific to XD are reachable via the require
method. Examples include scenegraph
, application
, uxp
, and more.
Example:
Copied to your clipboardconst { Text, Color } = require("scenegraph");