Skip to main content
nguyen_dang
March 31, 2023
Solved

referenceError: "blob" and "Buffer" is not defined

  • March 31, 2023
  • 3 replies
  • 2033 views

Hi folks. I’m trying to export frame to PNG and convert it to another format.

Library I use: webp-converter-browser

I use webpack to bundle all things. looks good.

But when I use the plugin on Figma environment, I always get the error:

referenceError: “blob” is not defined.

then I change from using blob to Buffer, I got:

referenceError: “Buffer” is not defined.

Sometimes it says “Unhandled promises” as well.

Please help me on this.

My steps:

  • export current frame to PNG using exportAsync ( → Uint8Array)
  • convert the pngBytes to pngBlob
  • convert pngBlob to webpBlob
  • Download webpBlob

(I was trying using pngBuffer but still got similar problem)

This topic has been closed for replies.
Best answer by Gleb

Figma sandbox is quite limited in what APIs it provides. You need to send the necessary data to the UI part of the plugin (iframe) which has access to pretty much all browser APIs and process the data there. Then you can send the result back to the Figma plugin backend code to be able to do actions based on this data on the Figma canvas if necessary.

Relevant documentation: Creating a User Interface | Plugin API

3 replies

May 8, 2023

I am having the same problem. Did you manage to find a solution?

Gleb
GlebSolution
Power Member
May 8, 2023

Figma sandbox is quite limited in what APIs it provides. You need to send the necessary data to the UI part of the plugin (iframe) which has access to pretty much all browser APIs and process the data there. Then you can send the result back to the Figma plugin backend code to be able to do actions based on this data on the Figma canvas if necessary.

Relevant documentation: Creating a User Interface | Plugin API

May 8, 2023

Thank you. I was indeed trying to use new Blob in the code.ts file