It took a while to get it working, but there really is not much to the code. You need to pass the object to debug to a recursive method. In this case, I am developing a Contentstack widget, which is a form of UI extension, and I want to see what the extension framework provides. First, this code outputs the JSON of the entry selected in the content management UI, which provides a tree nav. Then it outputs some information about the extension object, its methods, and its values. The code descends into any properties of type object, showing the same information indented an additional level, and additional levels for their object descendants.
The “reflection” work is apparently fast, but there is some delay before the output appears on the console.
Below is the bare-bones code, which I subsequently incorporated into to the developer widget that I had developed previously.
Without saying anything about best practice, code quality, or testing, this seems to function with no adverse side-effects.