Use the js sdk to integrate an iframe so the users can create a heygen avatar without leaving your app

Import the script

<script src="https://static.heygen.ai/js/instant-frame.umd.js"></script>

Create an instance of the iframe

const instantAavatarWin = new window.InstantFrame({ host: 'https://app.heygen.com' });

You can open and close the iframe like this

// token created using the create_token API
instantAavatarWin.openWindow(token);
instantAavatarWin.closeWindow();

Then you can call these methods on the instantAvatarWin to consume events

instantAavatarWin.on('open', function () {})
instantAavatarWin.on('close', function () {})
instantAavatarWin.on('submitted', function (resp) {
  console.log(resp.id);
});