The Figma Plugin API runs in a sandboxed JavaScript environment with access to the document tree. Understanding how the main thread and UI iframe communicate, and how to persist data on nodes, is foundational to building Figma plugins.
0 / 5 completed
1 / 5
What is the entry point object for all Figma plugin API operations?
The figma global is the root of the Figma Plugin API. It is a PluginAPI object injected into the plugin's JavaScript sandbox and exposes the document tree, viewport, current user, notifications, and node creation methods. It is not accessible from the plugin's UI thread — only from the main thread.
2 / 5
What does figma.currentPage refer to?
figma.currentPage is the PageNode for the page the user has open. You append nodes to it with figma.currentPage.appendChild(node) and traverse its children to access all layers on the active page. Switching pages programmatically requires setting figma.currentPage = anotherPage.
3 / 5
How does a Figma plugin's main thread communicate with its UI iframe?
Figma plugin communication uses postMessage. The main thread sends to the UI with figma.ui.postMessage(data) and listens with figma.ui.onmessage = handler. The UI iframe sends to the main thread with parent.postMessage({ pluginMessage: data }, '*') and listens with window.onmessage. Only serialisable data crosses the boundary.
4 / 5
What does node.setSharedPluginData(namespace, key, value) do?
setSharedPluginData stores string data on a node in a way that persists in the Figma file and is readable by any plugin using the same namespace string. In contrast, setPluginData stores data visible only to the same plugin. Shared data is useful for interoperability between plugins or storing metadata for external tools.
5 / 5
What must a Figma plugin call when it has finished its work and no longer needs to run?
figma.closePlugin() signals Figma to terminate the plugin's main thread sandbox and close its UI. An optional message string can be passed to display a success notification: figma.closePlugin('Done!'). For plugins without a UI, calling closePlugin() at the end of the main thread code is mandatory to avoid leaving the plugin in a hanging state.