How to access discourse username from an iframe?

Is it possible to access the Discourse.User variable from an iframe which has the following code?

const loggedIn = parent.Discourse.User.current();
var quiz_taker = loggedIn.username;

I set DISCOURSE_ENABLE_CORS to true, however it is not working. (added the domain in settings as well) => then rebuilt the app