How to access user data inside a custom widget
This article shows developers how they can access the data properties of the currently logged in user from inside a custom widget.
Note: Custom widgets are rendered on the page inside an iframe, thus functions of the parent document/window are not directly accessible by the logic inside your widget.
Tip: Since the iframe that contains the widget is rendered directly on the page from the same domain, there are no CORs issues and this document outlines how to modify your code to access the parent document/window.
How to retrieve user data
Use the following code to access the data properties of the currently logged in user (Fig. 2.1):
(Fig. 2.1) Access user data within a custom widget.
The above script will output the following data for developers to work with (Fig 3.1):
(Fig. 3.1) Console output of user data.
To learn more about how an iframe can interact with the parent document, and vice-versa, check out this MDN article