Figma Support Forum

How to Calculate Prototype Viewport?

I am wondering if there is some way to calculate the prototype viewport from the selected node’s editor viewport.

My specific use case is to generate an embeddable prototype URL from a selected node, so that the user doesn’t have to actually start the prototype to get the embed code.

What I can’t figure out is the viewport coordinate system of a prototype, and whether I can extrapolate it based on the editor viewport (assuming that the selected node is zoomed in and centered).

I’ve figured out how to get the scale of the prototype, but the bounds and center coordinate system don’t seem to match up with what’s in the editor (I am not selecting a device frame for the prototype).

So when I hide the UI and call scrollAndZoomIntoView for a frame, I look up the bounds of the viewport, the center and the zoom. This works to get the zoom of the prototype.

The viewport center, for example, will be something like 293.5, 212.5

But when I check the prototype embed link, the center is set to 113, 171

So really, I’m trying just to see if I can somehow translate between the editor and prototype viewport bounds so I can programmatically create a prototype link.