How do I export layers in a document as PNG programmatically using UXP?

I am trying to export layers as png to a user-defined file location using a for loop. There is no clear documentation or examples on how to do this, and previous questions on this topic have vague answers. Does anyone have a code sample on how to do this?

I also tried the artboard export example here ( but the await function never returns and it’s hard to debug the callback function.