Figma Support Forum

Get relative position of plugin UI window to main Figma window

Is it possible to get the position of custom plugin UI windows relative to the main Figma window?

I’m working on a drag-and-drop plugin, and calculating the right offset relative to the position of the plugin UI itself against the canvas viewport and the main Figma window would be really helpful to more precisely place the object on dragEnd.

I think also in general, outside of drag-and-drop scenarios, this would be useful to be able to query from the API.

I know that you can get Figma window size from the plugin UI with the following:

let width = window.outerWidth
let height = window.outerHeight

So maybe look into some window properties? If that’s not going to work, I think simply placing objects in the center of the screen would be an ok solution. :grimacing:

Yes, I did look at window properties - I think the ones I want to access are blocked for security/cross-site reasons? This is an error I typically see when looking through the property tree for window from the console:

DOMException: Blocked a frame with origin "null" from accessing a cross-origin frame.
    at invokeGetter (<anonymous>:1:142)

At the moment, I just place objects always at 64, 64 (and take into consideration zoom level). It works fine for now, but would be ideal to drop an object at the dragEnd position, especially when one is working on a larger canvas.

I think you might be able to capture the plug-in window using the following:


Then you could look to capture its x/y position potentially.

Is that a known/documented object? Also, is YOUR_FIGMA_NAME the username? Not sure how that would work in a distributed plugin.

Not documented that I know but a standard JavaScript object for detecting window events.

The Figma name is because a distributed plugin is under your name. That can be replaced by the organisation name if it’s an org that distributes and should still work :blush:.